java - HtmlUnit Page response (Downloading File) -


so im trying use htmlunit go url once visit url downloads json file regarding data want. not sure how word in htmlunit how can result downloaded file.

i suck @ explaining here look

trying check user availability this

private static final string url = "https://twitter.com/users/username_available?username="; 

...

htmlpage page = webclient.getpage(url + users[finalusersindex]); 

so creates new page each username thing url + username returns json file of user availability. know how read json file problem this

java.lang.classcastexception: com.gargoylesoftware.htmlunit.unexpectedpage  cannot cast com.gargoylesoftware.htmlunit.html.htmlpage 

i on line

htmlpage page = webclient.getpage(url + users[finalusersindex]); 

i suppose need create new page response how since automatically downloads file instead of per se, clicking button downloads file. (correct me if im wrong)

sorry 4am

as name indicates, htmlpage page containing html. json not html.

as the documentation indicates;

the defaultpagecreator create page depending on content type of http response, htmlpage html content, xmlpage xml content, textpage other text content , unexpectedpage else.

(emphasis mine).

so, exception you're getting indicates, behavior observed documented behavior: you're getting page neither html, nor xml, nor text, unexpectedpage.

your code should be:

unexpectedpage page = webclient.getpage(url + users[finalusersindex]); 

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -