R6
asked on
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
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
ASKER
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(connecti onSocket.g etInputStr eam)));)??
many thanks
r6
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()
many thanks
r6
You need to look at the source:
http://heanet.dl.sourceforge.net/sourceforge/jetty/jetty-5.1.3-src.zip
http://heanet.dl.sourceforge.net/sourceforge/jetty/jetty-5.1.3-src.zip
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
hi objects,
u mean first read the specified Content-Length value and then use this value in inputFromClient.read(cbuf, 0,contentL engthInt), 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
u mean first read the specified Content-Length value and then use this value in inputFromClient.read(cbuf,
Also, when would the content length of the message be 1? when get and head method are encountered?
many thanks
r6
yes thats right. Content length will be -1 when it is unknown in which case you read until eof.
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/
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/
>> 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.
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.
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).
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).
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).
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).
>> 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 ;)
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 ;)
ASKER
hi objects,
sorry for this late rewarding, i thought i had done it already. sorry again
many thanks r6
sorry for this late rewarding, i thought i had done it already. sorry again
many thanks r6
thats ok :)
http://jetty.mortbay.org/jetty/