« Return to Thread: HTTPResponse

Re: HTTPResponse

by Charles François Rey :: Rate this Message:

Reply to Author | View in Thread

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@...
For additional commands, e-mail: httpclient-users-help@...

 « Return to Thread: HTTPResponse