English 中文(简体)
HTTP 以 URL 作为参数的 Post 请求
原标题:HTTP Post request with URL as parameter

I need send https request to server using parameters one of them is URL: I do next:

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, 比如年龄, 性别等等。 我没有错误 。 我做错了吗?

问题回答

我没有接触到 apache 组件库 。 但是, 在 < a href= > 上查看 < http:// www.docjar. org/docs/ api/ apache/ http/ message/ BasicName ValuePair.html" rel= "nofollow" > 基本名 ValuePair , 我理解输入的名称和值是原始存储的,而不是 < em> encoded < /em> 。 恐怕这就是为什么您的 < code> url 参数的价值抛出错误的原因。 您可能需要 < a href=" http://hc.apache.org/ httpsuppres-client-ga/ httpclient/apicos/org/apache/ http/client/entity/ UrlEncodedFormentity.html" " rel=" "nofol " > > > > > 。 除非已经使用处理 ur ecocodedfordd FormentFormentity

试试这个...

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

}




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签