Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 557
narendra Avatar asked Jun 25 '12 05:06

narendra


1 Answers

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);
}
like image 167
narendra Avatar answered Oct 20 '22 05:10

narendra