Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

HTTP GET and POST requests

 
Joe Harry
Ranch Hand
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not quite sure if this question belongs to this forum. If not appropriate, please move this to the relevant forum:

I have the following questions:

1. Does a GET HTTP request contain a request body? If yes what is contained in it? Are the request headers also part of the request body?
2. Is it possible to send a byte array as part of the GET request in its body?
3. Is there a size limitation on the data that can be sent via a GET request?
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
#1 - No and no.

#2 - Answered by #1.

#3 - Define "data". You can send data as part of the headers, and I don't think there's a limit defined in the HTTP spec. But in practice any given HTTP client and any given HTTP server probably has a -possibly unspecified- upper limit as to how much it can handle. Also see http://stackoverflow.com/questions/3091485/what-is-the-limit-on-querystring-get-url-parameters
 
Joe Harry
Ranch Hand
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the clarification. We have a scenario wherein we are sending some data to the server and the server responds back with a response. Now since the data is huge (4 MB zipped down to 0.3 MB), I'm using HTTP POST to send data to the server, but all I'm doing on the server is just doing some calculations and returning the results. I'm not doing any update to the database or any file system. So in my scenario, a GET request would be the ideal option, but since GET cannot handle zipped data sent as a byte array in the request body, I'm using POST. Is this a valid reason to use POST? Am I doing it correctly?
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not sure what you mean by "valid reason" - compared to what alternatives?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65530
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A POST is perfectly appropriate. You are not getting a resource, you are sending. No one ever said you had to update a database during a post.
 
Tim Holloway
Bartender
Posts: 18415
58
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Technically, you can include a body with a GET request. But that's sloppy and counter to the intent of the spec.

There was never a formal limit set on the length of a GET command string, but early systems often wouldn't handle anything longer than 2000 characters or so. For longer stuff, POST would be safer.

As others have said, you're POSTing to the web server, not to a database server. Nobody ever said a web server had to have any databases attached to it.
 
Joe Harry
Ranch Hand
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for all your responses. As far as I could remember reading something about GET and POST requests from the Head First Servlet's and JSP book where they talk about Idempotent, I vaguely remember them referring to making updates to a database. Of course I could have a POST request and not change any state on my server and return a result back which makes me now comfortable to think that I used the right HTTP verb in my case.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!