apache commons httpclient - Java HTTP Post Raw Data -
I'm looking to request an HTTP post near a raw data that I have Have spent some time, have made a few handfuls and I'm looking for some help. What I'm looking to do is look at the PHP code like this:
& lt ;; $ Url = "http: // localhost: 3000"; $ Postdata = "& lt ;? Xml version = \" 1.0 \ "encoding = \" UTF-8 \ "? Gt; & gt; & lt; hi & gt; & lt; / hi & gt;"; $ Ch = curl_init ($ url); Curl_setopt ($ CH, CURLOPT_POST, 1); Curl_setopt ($ CH, CURLOPT_HEADER, 0); Curl_setopt ($ CH, CURLOPT_RETURNTRANSFER, 1); Curl_setopt ($ ch, CURLOPT_POSTFIELDS, $ postdata); $ Result = curl_xac ($ CH); Curl_close ($ ch); Echo ($ result); ? & Gt;
My attempt was to:
javas.io.IOException throws private string setXmlPostHeader (document doc, post-method post-method), java. Io.UnsupportedEncodingException, javax.xml.transform.TransformerException {BiteArrayOnputTream xmlBytes = new byteOnputStream (); XML.serialize (doctor, xmlbytes); Last byte [] ba = xmlBytes.toByteArray (); String data = new string (BA, "UTF-8"); InputStreamRequestEntity re = new InputStreamRequestEntity (new bytereinputstream (BA)); PostMethod.setRequestEntity (again); PostMethod.setRequestHeader ("content-type", mediaType.exml. string () + "; charset = UTF-8"); Return data; }
and then execute the postMethod, but this is just a post that has no data. Is there anything wrong that I am doing? I want to know how to change this method to actually work. Thanks!
-Cain
Will the class not work better?
Comments
Post a Comment