1

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?

Joshua Beckers
  • 857
  • 1
  • 11
  • 24

2 Answers2

4

you can use dio request instead

await dio.request(
  "/test",
  data: {"id": 12, "name": "xx"},
  options: Options(method: "GET"),
);
Pavel Shastov
  • 2,657
  • 1
  • 18
  • 26
0

With dio configure your Options widget like following to avoid redirection for the first request:

Options(
        followRedirects: false,
        validateStatus: (status) {
          return status < 500;
        }),

GET is not intended to send data, please see https://stackoverflow.com/a/60312720/10286880.

If you want to send them with POST you can do the following:

final res = await dio.post(
    '[YOUR ADRESS]',
    data: json.encode([YOUR BODY AS MAP])
  );
Milvintsiss
  • 1,420
  • 1
  • 18
  • 34
  • Unfortunately using POST does not work and I have to use GET. I don't know why it is implemented that way by Google since it is as you say against spec. – Joshua Beckers Mar 07 '21 at 23:41