Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed to parse header value #20

Open
ismailme33 opened this issue Oct 17, 2024 · 0 comments
Open

Failed to parse header value #20

ismailme33 opened this issue Oct 17, 2024 · 0 comments

Comments

@ismailme33
Copy link

ismailme33 commented Oct 17, 2024

Hi Dear

getting
this error


Restarted application in 453ms.
flutter: HTTP Code: null
flutter: API Error: null
flutter: Request Error: ClientException: Failed to parse header value
flutter: API Response: null


my code,

import 'package:flutter/material.dart';
import 'package:whatsapp/whatsapp.dart';

void main() => runApp(MaterialApp(home: Home()));

class Home extends StatefulWidget {
  const Home({super.key});

  @override
  State<Home> createState() => _HomeState();
}

class _HomeState extends State<Home> {
  late WhatsApp whatsapp; // Declare as late to initialize later

  final String accessToken1 =
      'myaccesstoken';
  final String fromNumberId = 'myphonenumberid';

  @override
  void initState() {
    super.initState();

    // Initialize WhatsApp instance here
    whatsapp = WhatsApp(accessToken1, fromNumberId);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: ListView(
        children: [
          TextButton(
            onPressed: () async {
              if (whatsapp != null) {
                try {
                  var res = await whatsapp.sendMessage(
                    phoneNumber: '+919019.....',
                    text: 'Hello from Flutter!',
                    previewUrl: true,
                  );

                  if (res.isSuccess()) {
                    debugPrint('Message ID: ${res.getMessageId()}');
                    debugPrint('Message sent to: ${res.getPhoneNumber()}');
                    debugPrint('API Response: ${res.getResponse().toString()}');
                  } else {
                    debugPrint('HTTP Code: ${res.getHttpCode()}');
                    debugPrint('API Error: ${res.getErrorMessage()}');
                    debugPrint('Request Error: ${res.getError()}');
                    debugPrint('API Response: ${res.getResponse().toString()}');
                  }
                } catch (e) {
                  debugPrint('Error: $e');
                }
              } else {
                debugPrint('WhatsApp is not initialized!');
              }
            },
            child: const Text("Send Message"),
          ),
        ],
      ),
    );
  }
}

could you please someone help me to sort out the issue?

image
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant