Jonathan Raes
Jonathan Raes

Reputation: 5

JSoup request url changes

Im trying to access an online api in java using JSoup. Through my browser i can navigate just fine to the url and i get json data in return. If I use Jsoup however, the url gets changed and '/api' is removed from it. Example is: https://www.onehash.com/api/archived_contest/122/ I can open it just fine in by browser but if I connect to it using jsoup the url becomes https:/ /www.onehash.com/archived_contest/122/ and a 404 error is returned. (space inserted because cant post more than 2 links) The overview url: https://www.onehash.com/api/disciplines_json/ I can connect to just fine with Jsoup though...

Does anyone have an idea on wht this happens? Ive tried sending an useragent in the header but to no avail.

The code I use to connect is:

Jsoup.connect("https://www.onehash.com/api/archived_contest/122")
     .userAgent("Mozilla")
     .ignoreContentType(true)
     .get();

which throws an HttpStatusException.

Upvotes: 0

Views: 357

Answers (1)

Nazarii Bardiuk
Nazarii Bardiuk

Reputation: 4342

With a slash on the end it works:

//                                                             v--- Slash here
Jsoup.connect("https://www.onehash.com/api/archived_contest/122/")
     .userAgent("Mozilla")
     .ignoreContentType(true)
     .get();

It also returns a 404 in the browser without the trailing slash.

Upvotes: 2

Related Questions