當使用url「https://www.parcelhero.com」時,代碼會將http響應代碼設爲403,儘管網站已成功打開並且實際響應代碼爲200.請告訴我原因。HTTP響應代碼爲403而不是200,爲什麼?
try {
URL url = new URL("https://www.parcelhero.com");
HttpURLConnection connection = (HttpURLConnection)url.openConnection();
connection.setRequestMethod("GET");
connection.connect();
int code = connection.getResponseCode();
//e.printStackTrace();
System.out.println(code);
}
catch (IOException e) {
e.printStackTrace();
}
你嘗試使用'HttpsURLConnection'類而不是'HttpURLConnection'? http://stackoverflow.com/questions/9960998/using-httpurlconnection-and-httpsurlconnection-to-connect-to-an-https – dnapierata
是的,它也沒有給出預期的代碼。 – user2044296