我試圖發送一個簡單的GET請求,因爲它是在這裏解釋:Using java.net.URLConnection to fire and handle HTTP requests當我發送GET請求時,爲什麼會出現錯誤500?
我指向的網頁是:https://e-campus.hei.fr/ERP-prod/
而且我得到這個錯誤HTTP500:
Exception in thread "main" java.io.IOException: Server returned HTTP response code: 500 for URL: https://e-campus.hei.fr/ERP-prod/
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1436)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:234)
at GetWebPage.main(GetWebPage.java:14)
爲什麼我收到此頁錯誤?我寫將返回我任何其他網頁的源代碼,該代碼...
我的代碼:
public class GetWebPage {
public static void main(String args[]) throws MalformedURLException,
IOException {
URLConnection connection = new URL("https://e-campus.hei.fr/ERP-prod/").openConnection();
connection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.3) Gecko/20100401");
InputStream response = connection.getInputStream();
InputStreamReader isr = new InputStreamReader(response);
BufferedReader reader = new BufferedReader(isr);
StringBuilder sb = new StringBuilder();
String line = "";
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
System.out.println(sb.toString());
}
}
你能後你寫的代碼? – isNaN1247 2011-05-22 15:48:38
在daniweb上發佈了相同的東西。由於同樣的原因,沒有得到回覆,錯誤的描述,缺少代碼 – 2011-05-22 15:50:50