0

There's an external Flask backend, that I need to issue this request to using Axios:

    import axios from "axios";
    import FormData from "form-data";

    const formData = new FormData();
    formData.append("client", "client");
    formData.append("endpoint", "endpoint");

    const response = await axios.get(
      URL,
      {
        headers: {
          "User-Agent": client,
          ...formData.getHeaders()
        },
        data: formData,
      }
    );
    const { data } = response;

The snippet above is what Postman suggest, but the backend returns this error message:

400 Bad Request: The browser (or proxy) sent a request that this server could not understand.

The original cURL request works fine in Postman:

curl --location --request GET 'URL' \
--header 'User-Agent: client' \
--form 'client="client"' \
--form 'endpoint="endpoint"'
Omar Dulaimi
  • 846
  • 10
  • 30

1 Answers1

0
  • You can’t send form data as body in GET request, data in axios represent body and this just use for POST, PUT and PATCH.
  • You have to break your form data as Query Param in your GET request
  • If you want to send form data, the stander is to use POST request if you want to save or PUT?PATCH in case you want to update
  • Could you edit your answer to include a working snippet? The emphasis here is the request must be a GET. I do not have any control over the external API. The cURL above works fine from Postman, so maybe you can start by checking that. – Omar Dulaimi Jun 26 '22 at 11:44