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 "Wang, Michael (Matrix)" <Mi...@ichotelsgroup.com> on 2006/06/08 17:57:27 UTC
passing object
Is there a way to pass an object like HashTable by using httpclient?
Is that a correct way to do that like this:
In client side, serializing object to string and send it as URL post
parameter.
In the server side, de-serializing the string to object.
Thanks in advance.
--Michael
Re: passing object
Posted by Roland Weber <ht...@dubioso.net>.
Hello Michael,
>
> Is that a correct way to do that like this:
>
> In client side, serializing object to string and send it as URL post
> parameter.
>
> In the server side, de-serializing the string to object.
Almost correct. But you serialize to a byte array, not a string.
And you don't send it as a parameter, unless you want to pass
other parameters as well. If the serialized object(s) is all you
want to send, you send the byte array as the request entity.
http://jakarta.apache.org/commons/httpclient/apidocs/org/apache/commons/httpclient/methods/ByteArrayRequestEntity.html
If you want to have an advanced design, you can implement the
request entity interface directly and serialize the object to
the output stream in writeRequest(...):
http://jakarta.apache.org/commons/httpclient/apidocs/org/apache/commons/httpclient/methods/RequestEntity.html
If you want to pass additional parameters with your serialized
object, your options are:
a) send them as query parameters in the URL
b) use a multipart request entity and serialize to a PartSource
instead of a ByteArrayRequestEntity
http://jakarta.apache.org/commons/httpclient/apidocs/org/apache/commons/httpclient/methods/multipart/MultipartRequestEntity.html
http://jakarta.apache.org/commons/httpclient/apidocs/org/apache/commons/httpclient/methods/multipart/ByteArrayPartSource.html
hope that helps,
Roland
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org