Flutter/Dart http POST redirect send body via GET

Issue

I’m trying to POST data to a Google Sheets web app.

When I POSTdata to the endpoint I get a status 302 back. If I then POST the data to the new location I get a status 405.

It works when I use Postman but I can’t get it to work in Flutter.

Postman receives the 302 and then sends a GET request with my JSON payload as body. This seems to be against the GET specification but it works.

I tried the flutter HTTP package and DIO, both don’t let me send a body via GET. I tried DIO with and without followRedirects.

How can I send a body via GET in flutter?

Solution

you can use dio request instead

await dio.request(
  "/test",
  data: {"id": 12, "name": "xx"},
  options: Options(method: "GET"),
);

Answered By – Pavel Shastov

Answer Checked By – Pedro (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *