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 zarian <ri...@gmail.com> on 2009/06/05 08:20:24 UTC

HTTPResponse

Hope somebody can help me...

I got the HTTP response and able to retrieve the corresponding headers, but
the problem is the response comes with message body which is in xml
format... can someone help me provide the necessary code for to retrieve the
message body...

thanks... 


heres my code...


DefaultHttpClient client = new DefaultHttpClient();
        HttpGet httpget = new HttpGet(responseURL);
        Credentials defaultcreds = new UsernamePasswordCredentials(USERNAME,
PASSWORD);
        client.getCredentialsProvider().setCredentials(new
AuthScope(DEVSERVER, PORT, REALM), defaultcreds);
      
        System.out.println("Retrieving... ");
        try {

            HttpResponse convertedResponse = client.execute(httpget);
           
            System.out.println("Connection: " +
convertedResponse.getHeaders("Connection")[0].getValue().trim());
            System.out.println("Date: " +
convertedResponse.getHeaders("Date")[0].getValue().trim());
            System.out.println("Content-type: " +
convertedResponse.getHeaders("Content-type")[0].getValue().trim());
            System.out.println("Content-Length: " +
convertedResponse.getHeaders("Content-Length")[0].getValue().trim());
            
        } catch (Exception ex) {
            ex.printStackTrace(pw);
        }
-- 
View this message in context: http://www.nabble.com/HTTPResponse-tp23881232p23881232.html
Sent from the HttpClient-User mailing list archive at Nabble.com.


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


Re: HTTPResponse

Posted by Charles François Rey <ch...@epfl.ch>.
Well, you can do something like this:
	
	InputStream is = response.getEntity().getContent();
	Document doc = DocumentBuilderFactory.newDocumentBuilder().parse(is);

and then use the DOM API to do stuff with the doc.

Have a look at the javax.xml.parsers and javax.xml.xpath packages.

On 5 juin 09, at 08:20, zarian wrote:

>
> Hope somebody can help me...
>
> I got the HTTP response and able to retrieve the corresponding  
> headers, but
> the problem is the response comes with message body which is in xml
> format... can someone help me provide the necessary code for to  
> retrieve the
> message body...
>
> thanks...
>
>
> heres my code...
>
>
> DefaultHttpClient client = new DefaultHttpClient();
>        HttpGet httpget = new HttpGet(responseURL);
>        Credentials defaultcreds = new  
> UsernamePasswordCredentials(USERNAME,
> PASSWORD);
>        client.getCredentialsProvider().setCredentials(new
> AuthScope(DEVSERVER, PORT, REALM), defaultcreds);
>
>        System.out.println("Retrieving... ");
>        try {
>
>            HttpResponse convertedResponse = client.execute(httpget);
>
>            System.out.println("Connection: " +
> convertedResponse.getHeaders("Connection")[0].getValue().trim());
>            System.out.println("Date: " +
> convertedResponse.getHeaders("Date")[0].getValue().trim());
>            System.out.println("Content-type: " +
> convertedResponse.getHeaders("Content-type")[0].getValue().trim());
>            System.out.println("Content-Length: " +
> convertedResponse.getHeaders("Content-Length")[0].getValue().trim());
>
>        } catch (Exception ex) {
>            ex.printStackTrace(pw);
>        }

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