HttpPost URI未满

时间:2011-12-02 11:39:45

标签: android uri http-post

我想从链接中获取 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(); }

2 个答案:

答案 0 :(得分:2)

您正在尝试发出POST请求..但网址为GET请求

看这里:How to add parameters to a HTTP GET request in Android?

答案 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();
}
相关问题