在线: httpget.setEntity(new UrlEncodedFormEntity(nameValuePairs));
我收到的错误是: The method setEntity(UrlEncodedFormEntity) is undefined for the type HttpGet
HttpClient httpclient = new DefaultHttpClient();
// Add the header data for the request
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("phonenumber","12345"));
nameValuePairs.add(new BasicNameValuePair("authtoken", "12345"));
HttpGet httpget = new HttpGet(url);
httpget.setEntity(new UrlEncodedFormEntity(nameValuePairs));
// Execute HTTP Post Request
HttpResponse response = httpclient.execute(httpget);
Run Code Online (Sandbox Code Playgroud)
GET请求没有可以包含实体的主体,您要包含的参数应该内置到URL本身中.
一个干净的方法是使用URIBuilder:
URIBuilder builder = new URIBuilder();
builder.setScheme("http").setHost(host).setPort(port).setPath(yourpath)
.setParameter("parts", "all")
.setParameter("action", "finish");
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6786 次 |
| 最近记录: |