You are viewing a plain text version of this content. The canonical link for it is here.
Posted to httpclient-users@hc.apache.org by Pengqian <pe...@eds.com> on 2007/08/17 12:28:53 UTC

Problem by getting request entity on server side

Hi,

i am new to HttpClient, so it might be a simply question to somebody.

i want to send some serializeable data(not only some String) to the server
per PostMethod, so i do following at client side:
Hashtable table = new Hashtable();
table.put("name", "XXX");
table.put("RequestObject", serializeableObject );
        
byte[] buf = SerializationUtils.serialize(table);
PostMethod.setRequestEntity(entity);
client.executeMethod(PostMethod);

and at the server side:
byte[] buf = new byte[servletRequest.getContentLength()];
servletRequest.getInputStream().read(buf); 
Hashtable table = (Hashtable) SerializationUtils.deserialize(buf);

in this way i can not get the Hashtable again at server side. Logging
message shows that everytime there is always a different content received
from client than the original hashtable made by client. i can not get the
right content from request entity made by client.

could anyone please help me?

thanks and regards
-- 
View this message in context: http://www.nabble.com/Problem-by-getting-request-entity-on-server-side-tf4284936.html#a12197385
Sent from the HttpClient-User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org


Re: Problem by getting request entity on server side

Posted by Oleg Kalnichevski <ol...@apache.org>.
On Fri, 2007-08-17 at 03:28 -0700, Pengqian wrote:
> Hi,
> 
> i am new to HttpClient, so it might be a simply question to somebody.
> 
> i want to send some serializeable data(not only some String) to the server
> per PostMethod, so i do following at client side:
> Hashtable table = new Hashtable();
> table.put("name", "XXX");
> table.put("RequestObject", serializeableObject );
>         
> byte[] buf = SerializationUtils.serialize(table);
> PostMethod.setRequestEntity(entity);
> client.executeMethod(PostMethod);
> 
> and at the server side:
> byte[] buf = new byte[servletRequest.getContentLength()];
> servletRequest.getInputStream().read(buf); 

This is a completely wrong way of reading from an input stream. Please
refer to some documentation on working with Java's I/O streams. This
article may be a reasonable start:

http://articles.techrepublic.com.com/5100-22-1046098.html

Oleg 


> Hashtable table = (Hashtable) SerializationUtils.deserialize(buf);
> 
> in this way i can not get the Hashtable again at server side. Logging
> message shows that everytime there is always a different content received
> from client than the original hashtable made by client. i can not get the
> right content from request entity made by client.
> 
> could anyone please help me?
> 
> thanks and regards


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org