• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 208
  • Last Modified:

How to handle http post method?

hi experts,
im working on a simple web server program that meant to handle post method.  But, i just realized that the entity body of the post message, that is, the name and value pairs is not ended with crlf...so that means i cant use bufferedreader.readline to read it, because it will wait indefinitely.. So, what is the alternative??

thanks

r6
0
R6
Asked:
R6
  • 4
  • 3
  • 2
  • +2
1 Solution
 
CEHJCommented:
The best way is to look at how an open source web server handles this. Try:

http://jetty.mortbay.org/jetty/
0
 
R6Author Commented:
hi CEHJ,

im sorry i cant find relevent topics from the link...sorry.  Is there any other way that i can 'read' from browser instead of using inputFromClient.readLine() such that (bufferedreader inputFromClient = new BufferedReader(new InputStreamReader(connectionSocket.getInputStream)));)??

many thanks

r6
0
 
CEHJCommented:
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
objectsCommented:
If the content length of the message is -1 then read until EOF.
If it is not then read the number of bytes specified by the content length.
0
 
R6Author Commented:
hi objects,

u mean first read the specified Content-Length value and then use this value in inputFromClient.read(cbuf,0,contentLengthInt), where inputFromClient is of BufferedReader right?
Also, when would the content length of the message be 1? when get and head method are encountered?

many thanks

r6
0
 
objectsCommented:
yes thats right. Content length will be -1 when it is unknown in which case you read until eof.
0
 
aozarovCommented:
You can have a look at: http://www.onjava.com/lpt/a/3578
which explains about the HTTP protocol (including POST command) with code example for the http server and client.
For more about the HTTP protocol (without reading the rfc) -> http://www.jmarshall.com/easy/http/
0
 
Mayank SAssociate Director - Product EngineeringCommented:
>> when would the content length of the message be 1?

You mean -1? That would be the case for dynamically generated pages like JSPs. For static HTML pages, you will have a positive value of content-length.
0
 
aozarovCommented:
mayankeagle, Though your examples are correct I am not sure if they are relevant in this case
where the receiver is an http server.
From the RFC http://www.w3.org/Protocols/HTTP/1.0/draft-ietf-http-spec.html it seems that the
client must send content-length with HTTP POST commands (server should indicate an error if that is
not the case).
0
 
objectsCommented:
Sorry my earlier comments regards -1 were refering to the response, not the request.
For your case you can most likely assume that content length will be specified (though there are some special cases when it may not be, or should be ignored).
0
 
Mayank SAssociate Director - Product EngineeringCommented:
>> Though your examples are correct I am not sure if they are relevant in this case where the receiver is an http server

Ah, you're right there. I meant about cases when the response comes from the server to the client..... guess I read the question too fast ;)
0
 
R6Author Commented:
hi objects,

sorry for this late rewarding, i thought i had done it already. sorry again

many thanks r6
0
 
objectsCommented:
thats ok :)
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 3
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now