Jsoup方法的标题(字符串,字符串)是未定义的类型Connection.KeyVal
问题描述:
我使用Jsoup版1.9.2和有以下代码:Jsoup方法的标题(字符串,字符串)是未定义的类型Connection.KeyVal
public static String reQuest(String tUri, org.jsoup.Connection.Method Met, String postData) throws IOException {
Response res = null;
try {
res = Jsoup.connect(tUri)
.ignoreContentType(true)
.followRedirects(true)
.cookies(HandleSession.COOKIES)
.data(postData)
.header("X-Requested-With", "XMLHttpRequest")
.method(Met)
.timeout(10000)
.execute();
Util.log.finest(tUri);
}
catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return res == null ? null : res.body();
}
该错误是在这条线:
.header("X-Requested-With", "XMLHttpRequest")
它说:
的方法,报头(字符串,字符串)是未定义的类型Connection.KeyVal
但jsoup文件说,这种方法是可用于此参数:
https://jsoup.org/apidocs/org/jsoup/Connection.Response.html
我已经与jsoup的前一版本所使用的正是这种代码。
它有什么问题?
答
在Jsoup 1.9.2中,通过使用.requestBody而不是.data来设置请求体。我很抱歉,没有看到它。
啊,在Jsoup 1.9.2中,请求体必须使用.requestBody而不是.data来设置。我很抱歉,没有看到它。 – SiriSch
你应该添加这个答案 –