litesuits / android-lite-http

LiteHttp is a simple, intelligent and flexible HTTP framework for Android. With LiteHttp you can make HTTP request with only one line of code! It could convert a java model to the parameter and rander the response JSON as a java model intelligently.
http://litesuits.com?form=ghttp
Apache License 2.0
830 stars 347 forks source link

请求失败 #3

Closed jinguoliang closed 9 years ago

jinguoliang commented 9 years ago

我在请求这个连接时失败 String url = "http://wap.cmread.com/r/400270618/400644484/index.htm?vt=9&cm=M2040002"; getJson2: LiteHttpClient client = LiteHttpClient.newApacheHttpClient(this,"Mozilla/5.0"); Response res = client.execute(new Request(url)); return res.getString(); 但是使用org.apache的httpclient就能成功: HttpGet get = new HttpGet(url); HttpClient client = new DefaultHttpClient(); HttpResponse response = client.execute(get); log("status = " + response.getStatusLine()); log("content " + response.getEntity().getContentLength()); InputStream in = response.getEntity().getContent(); return getStringFromInputStream(in); 这个链接多次重定向, 错误是 02-05 10:45:07.936: W/System.err(18855): 服务器拒绝或无法提供服务, http status code 400, Bad Request, 请求错误(请检查语义和参数) 02-05 10:45:07.936: W/System.err(18855): at com.litesuits.http.impl.apache.ApacheHttpClient.readDataWithRetries(ApacheHttpClient.java:483) 02-05 10:45:07.941: W/System.err(18855): at com.litesuits.http.impl.apache.ApacheHttpClient.readDataWithRetries(ApacheHttpClient.java:473) 02-05 10:45:07.941: W/System.err(18855): at com.litesuits.http.impl.apache.ApacheHttpClient.readDataWithRetries(ApacheHttpClient.java:473) 02-05 10:45:07.941: W/System.err(18855): at com.litesuits.http.impl.apache.ApacheHttpClient.execute(ApacheHttpClient.java:216) 02-05 10:45:07.941: W/System.err(18855): at com.example.test.MainActivity.getJson2(MainActivity.java:117) 02-05 10:45:07.941: W/System.err(18855): at com.example.test.MainActivity$1.run(MainActivity.java:69)

litesuits commented 9 years ago

是因为重定向时把参数urlencode了,而litehttp在此encoding所以出错。新版版已经纠正,可pull最新。

jinguoliang commented 9 years ago

非常感谢