我想从链接中获取 json 信息: 的 http://android.forum-example.org/?a=1&b=2&c=3
但是 Log.v 告诉我在 request.setEntity(new UrlEncodedFormEntity(qparams))之后; 我的 URI 是: http://android.forum-example.org/?
我的错误在哪里?
码
try {
HttpClient httpClient = new DefaultHttpClient();
HttpPost request = new HttpPost("http://android.forum-example.org/?");
List<NameValuePair> qparams = new ArrayList<NameValuePair>(3);
qparams.add(new BasicNameValuePair("a", "1"));
qparams.add(new BasicNameValuePair("b", "2"));
qparams.add(new BasicNameValuePair("c", "3"));
request.setEntity(new UrlEncodedFormEntity(qparams));
Log.v("URI:", request.getURI().toString());
HttpResponse response = httpClient.execute(request);
} catch (IOException e) { e.printStackTrace(); }
答案 0 :(得分:2)
您正在尝试发出POST
请求..但网址为GET
请求
答案 1 :(得分:1)
使用HttpGet
代替HttpPost
:
try {
HttpClient httpClient = new DefaultHttpClient();
HttpGet request = new HttpGet("http://android.forum-example.org/?a=1&b=2&c=3");
Log.v("URI:", request.getURI().toString());
HttpResponse response = httpClient.execute(request);
} catch (IOException e) {
e.printStackTrace();
}