External Libraries

Jsoup set referrer example

Jsoup set referrer example shows how to set Jsoup referrer. Example also shows Jsoup default referrer as well as how to set Jsoup referrer of your choice.

What is the Jsoup default referrer?

Jsoup uses empty referrer header while connecting to the URL requested. This can be verified by running below given code.

Output

Note: You can check your referrer by visiting https://www.whatismyreferer.com website.

How to set Jsoup referrer (referer)?

Some of the websites do not work if “referer” header is not sent along with the request. You may get HTTP 403 error while accessing those websites using Jsoup, since Jsoup pass empty value for the “referer” header by default.

To set referrer or “referer” header, you can use referrer method of Connection class.

This method sets the HTTP referer header of the request.

Below given example shows how to set Jsoup referer to “http://www.google.com”.

Output

See Also:

Set Jsoup user agent example

Please let us know your views in the comments section below.

Tags
Join 1000+ fellow learners! Enter your email address below: