0
我試圖在Java的一個post請求使用Apache HTTP components
,當我把我的實體,在這條線構造UrlEncodedFormEntity(名單<的NameValuePair>,字符串)是在建設POST請求未定義的錯誤
httppost.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));
它說
"The constructor UrlEncodedFormEntity(List, String) is undefined" and I am not sure why.
這裏是我整個代碼
@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();
}
}
}
我搜索過的每個資源都顯示這是正確的方式,所以我不確定它爲什麼返回undefined。