0
這是請求應該如何看(在頂部):問題與連接到URL
這是我在Java代碼:
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
public class Main {
public static void main(String[] args) throws Exception{
URL url = new URL("http://ishin-global.aktsk.com");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setDoOutput(true);
conn.setRequestMethod("GET");
conn.setRequestProperty("/ping ", " HTTP/1.1");
conn.setRequestProperty("Host"," ishin-global.aktsk.com");
conn.setRequestProperty("Accept"," */*");
conn.setRequestProperty("X-Platform"," android");
conn.setRequestProperty("X-ClientVersion"," 3.1.2");
conn.setRequestProperty("X-Language"," en");
conn.connect();
String line;
BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
while ((line = reader.readLine()) != null) {
System.out.println(line);
}
reader.close();
}
的問題是,我不從服務器得到響應,但我得到這些錯誤:
Exception in thread "main" java.io.FileNotFoundException: http://ishin-global.aktsk.com
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1836)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1441)
at Main.main(Main.java:24)
我一直沒能弄明白,所以我問here.Thanks提前
在您的圖片中,網址以「https」開頭,而不是「http」。 – RealSkeptic
你檢查了回覆代碼/消息嗎?即''conn.getResponseMessage()' – Serge
我改變了'http'到'https',它仍然是相同的,我使用conn.getResponseMessage()時得到代碼404,但url有效 –