我试图连接并从here检索页面标题。如果我从链接中删除“.com”后面的所有内容,代码工作正常。下面的代码不起作用:爪哇 - Jsoup HTTP错误获取URL。状态= 405
try {
Document doc = Jsoup.connect("https://news.google.com/news/local/section/geo/Sammamish,%20WA%2098075,%20United%20States/Sammamish,%20Washington?ned=us&hl=en")
.data("query", "Java")
.userAgent("Chrome")
.cookie("auth", "token")
.timeout(3000)
.post();
String title = doc.title();
Log.d("hellomate", title);
}
catch (IOException e) {
Log.d("hellomatee", e.toString());
}
如果代码工作,标题返回的应该是“连顿华盛顿 - 谷歌新闻”。 该错误代码返回是: “org.jsoup.HttpStatusException:HTTP错误URL抓取状态= 405,URL = https://news.google.com/news/local/section/geo/Sammamish,%20WA%2098075,%20United%20States/Sammamish,%20Washington?ned=us&hl=en。”
是什么状态405是什么意思? Jsoup是否不允许我使用的那种网址?
谢谢。
入住此问:https://www.google.de/url?sa=t&source = web&rct = j&url = https://stackoverflow.com/questions/41487157/jsoup-http-error-fetching-url-status-405&ved=0ahUKEwiT6sf2s8jVAhWMOxQKHWaSDmMQFggfMAE&usg=AFQjCNHU8QpL9rsnlQ2naxyoJPH-FQcuiA – Thomas
405是“方法不允许”,这意味着您的POST不是允许此资源(URL)。尝试获得(),如果你只是想获得的东西 – Andreas