Announcement Announcement Module
No announcement yet.
Message body with HTTP GET Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Message body with HTTP GET


    I've been wrestling with Spring Rest 3.1, trying to send an HTTP message body as part of a GET request. I don't seem to have any difficulty conveying such a body via POST, but it's not working for GET.

    I apologize for not having the code handy to post herein. I will post it when I get to work tomorrow.

    Here are the basics:

    postforentity works
    getforentity doesn't
    getforobject doesn't
    exchange doesn't

    I am serializing from object to json (and back) via Jackson. This seems to work well in the postforentity case.

    For the moment (until i can post the code), can anyone tell me if conveying a message body via GET is supported? I have seen conflicting reports on this including these two remarks from Fielding (emphasis mine):

    In general, most applications that involve user-supplied data being supplied to the server are not safe. The only exception is when the information is in the form of generalized query parameters, for which there is a trade-off between GET and POST that usually involves the size of the parameter content. GET is only desirable for those cases where the parameters can be expressed as a meaningful URI.

    Yes. In other words, any HTTP request message is allowed to contain a message body, and thus must parse messages with that in mind. Server semantics for GET, however, are restricted such that a body, if any, has no semantic meaning to the request. The requirements on parsing are separate from the requirements on method semantics. So, yes, you can send a body with GET, and no, it is never useful to do so.

    Thank you for your help.


  • #2
    As promised, here is the failing code from my Spring Rest client:
    	private ResponseEntity<NsbMsg> requestGetService(String svcUrl, NsbMsg nsbMsg)     
    		System.out.println(svcUrl + "::" + nsbMsg.diagTag);
    		RestTemplate myRestTemplate = new RestTemplate();
    		List<MediaType> acceptableMediaTypes = new ArrayList<MediaType>();
    		HttpHeaders headers = new HttpHeaders();
    		HttpEntity<NsbMsg> request = new HttpEntity<NsbMsg>(nsbMsg, headers);
    		ResponseEntity<NsbMsg> response =, HttpMethod.GET, request, NsbMsg.class);		return response;
    It fails as follows at the call to exchange():

    Exception in thread "main" org.springframework.web.client.HttpClientErrorException: 400 Bad Request
    	at org.springframework.web.client.DefaultResponseErrorHandler.handleError(
    	at org.springframework.web.client.RestTemplate.handleResponseError(
    	at org.springframework.web.client.RestTemplate.doExecute(
    	at org.springframework.web.client.RestTemplate.execute(
    What is "bad" about this request? I am stumped and would be most grateful for some help. Thanks.



    • #3

      Should I cross-post to the "Web" board?