Hi, Roland, Sorry for my poor English.
Let me describe my problem more precisely. I want to send a XML content (actually it's a String object contains XML content) through an OutputStream to the server by POST method. The server is a servlet hosting by Struts. In the Struts MVC, a servlet called LoginXml action will received the client post request. The action servlet (LoginXml) has a default Struts method like "public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)" I can use request.getReader() to read input buffer from the POST method of client. The client use HttpURLConnection.getOutputStream() to output the XML content to the remote server. Because the server use Reader to read an input stream, so the client and server will cooperate correctly. (it works for a long time) Now, I want to use HttpClient to replace HttpURLConnection. So I read the 4 documents (include Client HTTP Programming Primer, Guided Tour of HttpCore, Application Design FAQ, and Connection Management FAQ) at http://wiki.apache.org/HttpComponents/FrontPage I still run the examples of HttpClient 4.0-alph2 and HttpCore 4.0-beta1 release. But I still can't find there is a method or any way to replace HttpURLConnection.getOutputStream() function. And I see the suggestion you give me at http://hc.apache.org/httpcomponents-core/httpcore/apidocs/org/apache/http/Ht tpEntity.html#writeTo(java.io.OutputStream) I don't know where to generate the OutputStream for HttpEntity.writeTo(). You mean that I need to implement it (ObjectOutputStream) for myself? If I use ByteArrayEntity and set it to the HttpEntities at client-side code, does the server-side code need to use HttpCore or HttpClient library to receive the request? I just want to change the client-side code. I don't want to change the server-side code. Does there any examples let me figure out how the post an object request work? Thank you very much!! >> 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? It's just a String object. > Did you implement a custom HttpEntity? Do you use one of the > standard entities with your own file/byte array/string? I didn't implement a custom HttpEntity. I use the ByteArrayEntity with my string to POST to server, but the server receive "null." > What do you mean with "set to HttpClient"? HttpEntities are set > on requests, which get executed at an HttpClient. I try the ByteArrayEntity and InputStreamEntity to get executed at an HttpClient, but the server receive "null." >> 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? The server get "null" from request.getParameter() when I use HttpPost.setParameter(). The server get "null" from request.getAttribute() when I use HttpContext.setAttribute(). The server get "null" from request.getReader() when I use the same code as ClientChunkEncodedPost.java in HttpClient's examples. >> 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. > [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/en tity/ByteArrayEntity.html > [3] > http://hc.apache.org/httpcomponents-core/httpcore/apidocs/org/apache/http/Ht tpEntity.html#writeTo(java.io.OutputStream) I am trying the ObjectOutputStream now. I hope I can figure out the magic POST issues soon. Thanks for your help in advance. Sincerely, Micky --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
