http - Capture the URI, resource name,as seen in Developer Tools, from GET POST request method in Java -
i doing part of enhancing selenium webdriver script. have tried using httpclient java , lot of other things not able anywhere. please help!
ths scenario:
after action performed in webpage button click, get/post methods can seen in developer tools in chrome.
i have taken example of google here.
what need here collect resource names until resource appears (if open developer tools in chrome , navigate google.com , under network tab on leftmost column see tia.png , example).
there 2 things should achieved:
ensure resource loaded
make sure page loaded (all / post methods have been transferred) before other action taken.
the httpclient, httpurlconnection capture 1 request, page sends lot of requests. how capture of them?
by using http apache client , can use :- solve problem, can response code "response.getstatusline().getstatuscode()" , check expected response code , can play outcome of response.
uri url = new uri("string uri"); defaulthttpclient client = new defaulthttpclient(); httppost post = new httppost(url); httpresponse response = httpclientbuilder.create().build().execute(post); system.out.println("response code : " + response.getstatusline().getstatuscode()); bufferedreader rd = new bufferedreader(new inputstreamreader(response.getentity().getcontent())); stringbuffer result = new stringbuffer(); string line = ""; while ((line = rd.readline()) != null) { result.append(line); } system.out.println("ressponse 1 >>>>"+result.tostring());
and , if need send parameters in post request :-
list<namevaluepair> urlparameters = new arraylist<namevaluepair>(); urlparameters.add(new basicnamevaluepair("username", "yourusername")); urlparameters.add(new basicnamevaluepair("password", "yourpassword")); post.setentity(new urlencodedformentity(urlparameters));
Comments
Post a Comment