我正在使用http get請求在android中加載數據。不知道它返回的是html而不是JSON結果。當在瀏覽器中加載時,相同的URL會獲得json,但是會響應html。Http Get Request返回html?
我的HTTP GET調用格式就像這個...
url = new URL(urlString);
//httpURLConnection = (HttpsURLConnection) url.openConnection();
httpURLConnection = (HttpURLConnection) url.openConnection();
httpURLConnection.setRequestMethod("GET");
httpURLConnection.setRequestProperty("Connection", "keep-alive");
httpURLConnection.setRequestProperty("Accept", "application/json"); // or application/jsonrequest
httpURLConnection.setRequestProperty("Content-Type", "application/json");
/*
httpURLConnection.setRequestProperty("Content-Type",
"application/json");*/
httpURLConnection.setRequestProperty("UseCookieContainer", "True");
httpURLConnection.setRequestProperty("Cookie", cokieValue);
httpURLConnection.connect();
服務器如何決定發送哪種格式回來?你需要找到它,然後相應地編寫Android應用程序。 – Henry
看起來像你正在得到404 html頁面或其他一些錯誤 – injecteer
沒有先生我得到的響應代碼爲200,響應代碼只得到html – Sankar