【发布时间】:2017-04-11 05:15:19
【问题描述】:
当我在这一行设置我的实体时,我正在尝试使用Apache HTTP components 在 java 中发出 post 请求
httppost.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));
上面写着
“构造函数 UrlEncodedFormEntity(List, String) 未定义”,我不知道为什么。
这是我的全部代码
@Component
public class ScheduledTasks {
@Scheduled(cron="0 9 1-7 * 1 *") //first monday of each month, at 9am
public void dataLoaderTask() throws Exception {
HttpClient httpclient = HttpClients.createDefault();
HttpPost httppost = new HttpPost("https://erudite-master-api-awsmaui.lab.expts.net/erudite/search");
List<NameValuePair> params = new ArrayList<NameValuePair>(3);
params.add(new NameValuePair("action", "count"));
params.add(new NameValuePair("fields", "Status"));
params.add(new NameValuePair("filters", ""));
httppost.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));
//Execute and get the response.
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
if (entity != null) {
InputStream instream = entity.getContent();
try {
// do something useful
} finally {
instream.close();
}
}
}
我搜索过的每个资源都表明这是这样做的正确方法,所以我不确定它为什么返回未定义。
【问题讨论】: