【发布时间】:2014-09-02 05:38:28
【问题描述】:
我正在使用一段代码从服务器获取 json 文件,该文件确实存在于服务器上,但 httpUrlConnection 保持返回 responseMessage“未找到” 这是我的代码
private void openHttpUrlConnection(String urlString) throws IOException {
Log.d("urlstring in parser", urlString + "");
URL url = new URL(urlString);
URLConnection connection = url.openConnection();
httpConnection = (HttpURLConnection) connection;
httpConnection.setConnectTimeout(30000);
httpConnection.setRequestMethod("GET");
httpConnection.connect();
Log.d("connection",httpConnection.getResponseMessage());
}
当我切换到 httpClient 时,它对于相同的 url 可以正常工作
private void openHttpClient(String urlString) throws IOException {
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpParams httpParams = httpClient.getParams();
HttpConnectionParams.setConnectionTimeout(httpParams, 30000);
HttpGet httpGet = new HttpGet(urlString);
HttpResponse httpResponse = httpClient.execute(httpGet);
HttpEntity httpEntity = httpResponse.getEntity();
inputStream = httpEntity.getContent();
reader = new BufferedReader(
new InputStreamReader(inputStream, "UTF-8"), 8);
}
json文件的url是http://aizariacouncil.org/products.json
【问题讨论】:
-
当我试图去这里aizariacouncil.org 然后同样的问题
-
转到aizariacouncil.org/products.json,网站中的索引文件现在已经损坏,但是json文件存在并在浏览器中打开,请仔细检查
-
尝试先解决问题,然后才来
-
现在试试aizariacouncil.org,问题不断出现
标签: android json httpclient httpurlconnection android-4.4-kitkat