0
我使用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來設置。我很抱歉,沒有看到它。 – SiriSch
你應該添加這個答案 –