0

我需要使用参数向服务器发送 https 请求,其中一个参数是 URL:我接下来要做:

HttpClient httpClient = new DefaultHttpClient();
    HttpPost httpPost = new HttpPost(APIURL);
    httpPost.setHeader("Content-Type", "application/x-www-form-urlencoded");
    List<NameValuePair> params = new ArrayList<NameValuePair>();
    params.add(new BasicNameValuePair("url", "https://api/v1/pictureadress/id"));
 ...

添加 URL 参数时出现错误。但是,如果我添加除 url 之外的其他参数,例如年龄、性别等。我没有错误。我做错了什么?

4

2 回答 2

0

我没有接触过 apache 组件库。但是查看BasicNameValuePair上的 api ,我知道输入名称和值是原始存储的,而不是编码的。我担心这就是您的url参数值引发错误的原因。您可能需要UrlEncodedFormEntity,除非已经用于处理 url 编码的名称值对。

于 2012-05-28T15:12:39.533 回答
0

尝试这个..

public void postData() throws Exception {


 HttpClient client = new DefaultHttpClient();
 HttpPost httppost = new HttpPost("http://www.xyz.com");

 List<NameValuePair> list = new ArrayList<NameValuePair>(1);

 list.add(new BasicNameValuePair("name","ABC");

 httppost.setEntity(new UrlEncodedFormEntity(list));

 HttpResponse r = client.execute(httppost);

}
于 2012-05-28T15:33:03.000 回答