我正在使用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