我有这个URL(其执行在浏览器罚款):我如何搞乱我的HttpGet参数编码?
https://api-test.company.com/contacts/[email protected]
,我想使用HttpClient的执行。我已经试过:
String URL = "https://api-test.company.com/contacts?q=" + URLEncoder.encode("[email protected]");
DefaultHttpClient client = new DefaultHttpClient();
HttpGet c = new HttpGet(URL);
HttpResponse response = client.execute(c);
String resultContent = myRestCall.GetResponseText(response);
这将返回错误:
QUERY_PARAMunable分析查询字符串 '[email protected]'
我已经试过:
GetMethod method = new GetMethod("https://api-test.company.com/contacts/?q=");
method.setQueryString(new NameValuePair[] {new NameValuePair("email", "[email protected]")});
HttpGet c = new HttpGet(method.toString());
DefaultHttpClient client = new DefaultHttpClient();
HttpResponse response = client.execute(c);
返回:
java.lang.IllegalStateException:目标主机不能为空,或者在参数中设置。
那么我该如何正确解析这个简单的GET请求呢?
谢谢。
正确地说谁是正确的。 –
我不确定我明白你在问什么。我问如何正确执行GET请求与给定的参数。 – Jason