通过vpnbook.com访问网站

时间:2016-09-02 08:31:25

标签: java https proxy

我正致力于通过vpnbook.com访问网页的应用程序。

我的代码是将帖子请求发送到网址" https://webproxy.vpnbook.com/includes/process.php?action=update"邮政机构为" u = yahoo.com& webproxylocation = random" 我收到响应代码302. HTTP响应头包含位置

"位置= [http://www.vpnbook.com/webproxy]"

但是同样的要求在通过网络浏览器打开时获得了正确的正确结果。

结果包含标头响应 "位置:https://usproxy.vpnbook.com/browse.phpu=DWnjEwVwhlG5GQhW&b=0&f=norefer"

请告诉我我的代码出了什么问题。

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 to 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(); }

0 个答案:

没有答案