HttpPost URI 不完整
我想从链接获取 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您正在尝试发出
POST
请求..但 url 的类型为GET
请求请查看此处:如何在 Android 中向 HTTP GET 请求添加参数?
You are trying to make a
POST
request.. but the url is of typeGET
requestlook here : How to add parameters to a HTTP GET request in Android?
使用
HttpGet
而不是HttpPost
:Use
HttpGet
instead ofHttpPost
: