HttpPost URI 不完整

发布于 2024-12-19 08:04:51 字数 933 浏览 0 评论 0原文

我想从链接获取 json 信息: http://android.forum-example.org/?a=1&b=2&c=3

Log.v 告诉我,在请求之后.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(); }

I want to get json info from the link:
http://android.forum-example.org/?a=1&b=2&c=3

but Log.v tells me that after request.setEntity(new UrlEncodedFormEntity(qparams));
my URI is: http://android.forum-example.org/?

Where is my mistake?

code:

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(); }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

单身情人 2024-12-26 08:04:51

您正在尝试发出 POST 请求..但 url 的类型为 GET 请求

请查看此处:如何在 Android 中向 HTTP GET 请求添加参数?

You are trying to make a POST request.. but the url is of type GET request

look here : How to add parameters to a HTTP GET request in Android?

当梦初醒 2024-12-26 08:04:51

使用 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();
}

Use HttpGet instead of 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();
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文