Is HttpURLConnection can Solve my problem if SO how ?
1 posts in topic
Flat View  Flat View

Posted By:   Anoop_KumarA
Posted On:   Wednesday, March 28, 2001 09:06 AM

How can make an HTTP Post request where my request is an XML page and the response is also XML

Re: Is HttpURLConnection can Solve my problem if SO how ?

Posted By:   Zachary_Hunter  
Posted On:   Wednesday, March 28, 2001 12:19 PM

Here's how to do it using just a URLConnection. It might not handle all the protocol specific errors, but should work fine fundimentally. Here's what you do:

//Create URL to post to
URL url = new URL("http://your.url.here");

//get connection to URL
URLConnection urlConn = url_.openConnection();

//prepare for writing request data

//get output stream from URLCon
PrintWriter out = new PrintWriter(urlConn.getOutputStream());

//write the request data to stream

//close the output connection

//get response from post request
BufferedReader xmlIn = new BufferedReader(new InputStreamReader(urlConn.getInputStream()));

//prepare to read in content
StringBuffer response = new StringBuffer();
Strint line;

//read in all the xml
while((line = inXML.readLine()) != null)

Rather than reading the response into a StringBuffer, you could just use the input stream to create an InputSource to pass to a SAX parser's parse() method.

About | Sitemap | Contact