i working on application access web page through vpnbook.com.
my code sending post request url "https://webproxy.vpnbook.com/includes/process.php?action=update" post body "u=yahoo.com&webproxylocation=random" getting response code 302. , http response header contains location
"location=[http://www.vpnbook.com/webproxy]"
but same request getting correct correct result when opening through web browser.
result contains header response "location:https://usproxy.vpnbook.com/browse.phpu=dwnjewvwhlg5gqhw&b=0&f=norefer"
please tell me going wrong in code.
try{ url url = new url("https://webproxy.vpnbook.com/includes/process.php?action=update"); httpsurlconnection c = (httpsurlconnection) url.openconnection(); c.setrequestproperty("user-agent", user_agent); c.setrequestproperty("accept-language", accept_lang); c.setrequestproperty("accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"); c.setrequestproperty("host", "webproxy.vpnbook.com"); c.setrequestproperty("origin", "http://www.vpnbook.com"); c.setrequestproperty("referer", "http://www.vpnbook.com/webproxy"); c.setrequestmethod("post"); c.setdoinput(true); c.setdooutput(true); dataoutputstream wr = new dataoutputstream(c.getoutputstream()); wr.writebytes("u=yahoo.com&webproxylocation=random"); wr.flush(); wr.close(); int responsecode = c.getresponsecode(); system.out.println("\nsending 'get' request url : " + url); system.out.println("response code : " + responsecode); system.out.println("response headers : " + c.getheaderfields()); map<string, list<string>> reshdr = c.getheaderfields(); if( reshdr.containskey("set-cookie") ){ cookies=reshdr.get("set-cookie").tostring(); cookies = cookies.replaceall("\\[|\\]", ""); system.out.println(cookies); } bufferedreader in = new bufferedreader(new inputstreamreader(c.getinputstream())); string inputline; stringbuffer response = new stringbuffer(); while ((inputline = in.readline()) != null) { response.append(inputline); } in.close(); system.out.println(response); }catch(exception ex) { ex.printstacktrace(); }
Comments
Post a Comment