Sending Request body for GET method in AXIOS throws error

techie_questie

I have a React application where I am changing POST method to GET with the request body as it is. It works fine with POST request however when I change the method to GET, it gives me error-

message: "org.springframework.http.converter.HttpMessageNotReadableException: Required request body is missing: public 

My Front End Code-

export const setData = (getData)  => dispatch => {
    axios({
        method: 'GET',
        url: 'http://localhost:8080/api',
        headers: {
          'Content-Type': 'application/json'
        },
        data: getData
      })
      .then (response => {
      dispatch({
        type: API_DATA, 
        payload: response.data
      })
      dispatch({
        type: SET_SEARCH_LOADER, 
        payload: false
      })
      })
      .catch(function(error) {       
      })
}

Can someone let me know what I am missing here. As per my understanding, http allows to have a request body for GET method.

Quentin

As per my understanding, http allows to have a request body for GET method.

While this is technically true (although it may be more accurate to say that it just doesn't explicitly disallow it), it's a very odd thing to do, and most systems do not expect GET requests to have bodies.

Consequently, plenty of libraries will not handle this.

The documentation for Axois says:

  // `data` is the data to be sent as the request body
  // Only applicable for request methods 'PUT', 'POST', and 'PATCH'

Under the hood, if you run Axios client side in a web browser, it will use XMLHttpRequest. If you look at the specification for that it says:

client . send([body = null])

Initiates the request. The body argument provides the request body, if any, and is ignored if the request method is GET or HEAD.

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

Sending GET request parameters in body

分類Dev

axios get request Error: Request failed with status code 504

分類Dev

"Error processing request body" occurs randomly when sending image in expo/react-native

分類Dev

401 HTTP error on basic auth GET request from Axios to API

分類Dev

Sending HTTP Post Request to site with array in Body

分類Dev

How to pass to the controller method request body?

分類Dev

GET request throws error after app implemented SSL: Mixed Content: This request has been blocked; the content must be served over HTTPS"

分類Dev

jQuery .get function sending request multiple times

分類Dev

axios post request to MongoDB Atlas error 11000

分類Dev

Axios request returns error 500 (laravel, axios & vuejs)

分類Dev

Dynamic dropdown list react axios get request

分類Dev

How to get value from Axios request?

分類Dev

PHP - Get JSON body from HTTPS request

分類Dev

HTTP GET request with body for RESTful API

分類Dev

remove method throws error in List interface iterator

分類Dev

req.body undefined axios.get inreact-native

分類Dev

Why is server getting empty request.body from POST http request made with axios?

分類Dev

Unity Error: .ctor(): method body is empty

分類Dev

How do I make a GET request with JSON in the request body

分類Dev

How to get Params from url for Axios GET request?

分類Dev

sending array data with multipart/form-data post request in Axios vue.js

分類Dev

Cors error when sending a PUT request with ajax API

分類Dev

Is it possible a malicious website access to Anti Forgery Token by sending a get request?

分類Dev

I get the error that the body is not defined in expres?

分類Dev

Flask view function losing request arguments when sending a POST request after GET request

分類Dev

Axios catch error Request failed with status code 404

分類Dev

Axios post request to Firebase Auth REST API produces 400 error

分類Dev

Post request by axios (VueJS) in laravel giving 500 error

分類Dev

Failed to compile vue.js app due to axios get request

Related 関連記事

  1. 1

    Sending GET request parameters in body

  2. 2

    axios get request Error: Request failed with status code 504

  3. 3

    "Error processing request body" occurs randomly when sending image in expo/react-native

  4. 4

    401 HTTP error on basic auth GET request from Axios to API

  5. 5

    Sending HTTP Post Request to site with array in Body

  6. 6

    How to pass to the controller method request body?

  7. 7

    GET request throws error after app implemented SSL: Mixed Content: This request has been blocked; the content must be served over HTTPS"

  8. 8

    jQuery .get function sending request multiple times

  9. 9

    axios post request to MongoDB Atlas error 11000

  10. 10

    Axios request returns error 500 (laravel, axios & vuejs)

  11. 11

    Dynamic dropdown list react axios get request

  12. 12

    How to get value from Axios request?

  13. 13

    PHP - Get JSON body from HTTPS request

  14. 14

    HTTP GET request with body for RESTful API

  15. 15

    remove method throws error in List interface iterator

  16. 16

    req.body undefined axios.get inreact-native

  17. 17

    Why is server getting empty request.body from POST http request made with axios?

  18. 18

    Unity Error: .ctor(): method body is empty

  19. 19

    How do I make a GET request with JSON in the request body

  20. 20

    How to get Params from url for Axios GET request?

  21. 21

    sending array data with multipart/form-data post request in Axios vue.js

  22. 22

    Cors error when sending a PUT request with ajax API

  23. 23

    Is it possible a malicious website access to Anti Forgery Token by sending a get request?

  24. 24

    I get the error that the body is not defined in expres?

  25. 25

    Flask view function losing request arguments when sending a POST request after GET request

  26. 26

    Axios catch error Request failed with status code 404

  27. 27

    Axios post request to Firebase Auth REST API produces 400 error

  28. 28

    Post request by axios (VueJS) in laravel giving 500 error

  29. 29

    Failed to compile vue.js app due to axios get request

ホットタグ

アーカイブ