1

I'm trying to connect and retrieve the page title from here. The code works fine if I remove everything after ".com" from the link. The following code does not work:

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());
}

If the code worked, the title returned should be "Sammamish Washington - Google News". The error returned from the code is: "org.jsoup.HttpStatusException: HTTP error fetching URL. Status=405, URL=https://news.google.com/news/local/section/geo/Sammamish,%20WA%2098075,%20United%20States/Sammamish,%20Washington?ned=us&hl=en"

What does status 405 mean? Does Jsoup not allow the kind of url I used?

Thanks.

2
  • Check this q: google.de/url?sa=t&source=web&rct=j&url=https://… Commented Aug 8, 2017 at 19:49
  • 405 is "Method Not allowed" that means your POST is not allowed for this resource(URL). Try .get() if you only want to Receive something Commented Aug 8, 2017 at 19:49

1 Answer 1

0

Status 405 is an http error code that means "Method Not allowed". You can find some documentation from microsoft on it here. As @Andreas said, you can fix this by changing .post(); to .get();.

If you look at the jsoup docs under example, it shows you how you would probably want to structure your requests:

Jsoup.connect("http://en.wikipedia.org/").get();
Sign up to request clarification or add additional context in comments.

1 Comment

Why do some urls work with post and others only with get? Is there a way to get the headers of the page without using post?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.