【发布时间】:2013-04-20 07:19:30
【问题描述】:
我跟着this other SO question设置了URL参数,但是报错了:
HttpMethodBase类型中的方法setQueryString(String)不适用于参数(NameValuePair[])
和
无法实例化类型
NameValuePair。
我无法理解实际问题。有人可以帮我解决这个问题吗?
我从上述问题中使用的代码
GetMethod method = new GetMethod("example.com/page";);
method.setQueryString(new NameValuePair[] {
new NameValuePair("key", "value")
});
【问题讨论】:
-
你把这里多余的分号去掉了吗
"example.com/page"; -
您使用的是 httpclient 3.x 还是 4.x?您给出的示例是典型的 3.x 代码,而不是 4.x。
-
Vikingsteve 在执行代码时已经删除了分号
-
伟大的 NilsH 我正在使用 4.x.:)。使用 4.x 时如何设置参数?
-
@Anto 确定? 4.x 版本中没有 GetMethod 类。根据 javadoc,它是 HttpGet
标签: java http post get apache-httpclient-4.x