我正在使用HTTP GET请求在安卓中加载数据。但是不知道为什么返回的是HTML而不是JSON结果。当在浏览器中加载时,相同的URL会得到JSON,但响应却是HTML。
我的HTTP GET调用格式如下...
我的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();