How to POST to google form by Flutter. The response is always 400 (POSTMAN'S result is 200 OK)
After reproduce your case in Postman with form-data:
and for control, i'm using curl for testing :
curl --location --request POST 'https://docs.google.com/forms/u/0/d/e/1FAIpQLSc5aAwiiLJ2qJhF-ngGFfRl8m8yEJs8gTipY7pnNQkxGcJ_1w/formResponse' \ --form 'entry.844954850=bug' \ --form 'entry.479013015=dsfa'
now i can reproduce this Post request in flutter:
void _request() async { String url = 'https://docs.google.com/forms/u/0/d/e/1FAIpQLSc5aAwiiLJ2qJhF-ngGFfRl8m8yEJs8gTipY7pnNQkxGcJ_1w/formResponse'; Map<String, String> headers = { "Content-Type": "application/x-www-form-urlencoded", }; // String body = json.encode(...) //------------> Before Map<String, String> requestBody = <String, String>{ // After 'entry.844954850': 'bug', 'entry.479013015': 'dsfa' }; http.Response resp = await http.post(url, headers: headers, body: requestBody); print(resp); if (resp.statusCode != 200) { print('Failed to post ${resp.statusCode}'); } else { print(resp.body); }}
status code in debug mode:
For dio, it's same replace json and your request is formatted correctly.