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 "Micky(米其屁)" <mi...@gmail.com> on 2008/02/21 20:36:50 UTC

[help] how to set an OutputStream to a POST request?

I set the HttpEntity with my own object to HttpClient, the execute the post
request.

But the server can't get the object I set.

What I want to do is that only send a java object to the output stream of
that http connection instead of setAttribute.

The HttpContext, HttpEntity, and HttpParams seem not the solution?! ( I
used, and it doesn't work)

Any advise will be appreciated.

Thanks your help in advance.


-- 
Welcome to Micky's Home Page !

http://micky.hime2000.com

Re: [help] how to set an OutputStream to a POST request?

Posted by Roland Weber <os...@dubioso.net>.
Hello,

Micky(米其屁) wrote:
> I set the HttpEntity with my own object to HttpClient, the execute the post
> request.

Please be more specific. What do you mean with your own object?
Did you implement a custom HttpEntity? Do you use one of the
standard entities with your own file/byte array/string?
What do you mean with "set to HttpClient"? HttpEntities are set
on requests, which get executed at an HttpClient.

> But the server can't get the object I set.

Please be more specific. What does the server get? Is there an
error response? An exception? Unexpectedly closed connection?

> What I want to do is that only send a java object to the output stream of
> that http connection instead of setAttribute.

Where did you call setAttribute? If you want to serialize an
object, you have to use an ObjectOutputStream [1]. Either
serialize your object to a byte array which you can put into
a ByteArrayEntity [2], or implement your own entity that stores
the object and creates the ObjectOutputStream when writeTo [3]
is called.

hope that helps,
   Roland

[1] http://java.sun.com/j2se/1.5.0/docs/api/java/io/ObjectOutputStream.html
[2]
http://hc.apache.org/httpcomponents-core/httpcore/apidocs/org/apache/http/entity/ByteArrayEntity.html
[3] 
http://hc.apache.org/httpcomponents-core/httpcore/apidocs/org/apache/http/HttpEntity.html#writeTo(java.io.OutputStream)

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