narendra
narendra

Reputation: 451

How to get json page using httpunit

I am using web client. and login successfully through web client. but when i send second request for getting data . I got an Exception

com.gargoylesoftware.htmlunit.UnexpectedPage@6d8d73`

but when i pass url thruogh brouser i got a data Json format.

Code:

webClient.getPage("http://ajax/stream/refresh-box?r=new&id=2323222&")

Thx in advanced

Upvotes: 8

Views: 1472

Answers (2)

narendra
narendra

Reputation: 451

this is the which is reading different content type through web client

Page page = webClient.getPage(url);
System.out.println(page);
WebResponse response = page.getWebResponse();

if (response.getContentType().equals("application/json")) 
{
pagesource = response.getContentAsString();
System.out.println(pagesource);
}

Upvotes: 2

mazalo
mazalo

Reputation: 11

This URL is returning an error, if I type it in the browser, check it again: "http://ajax/stream/refresh-box?r=new&id=2323222&"

BTW, why does it finish with & sign while there is no additional parameter?

I removed the & sign and still I get no page exception in the browser.

Upvotes: 0

Related Questions