External Libraries Java Exceptions

Jsoup error 403 Forbidden exception fix

Jsoup error 403 Forbidden exception fix example shows how to fix error 403 – Forbidden exception while using Jsoup in Java. Jsoup throws “org.jsoup.HttpStatusException: HTTP error fetching URL. Status=403” exception.

How to solve error 403 – forbidden exception while using Jsoup?

When trying to parse a website, I encountered “org.jsoup.HttpStatusException: HTTP error fetching URL. Status=403”. Here is the code which was used.


HTTP status (response code) returned is 403.

What is HTTP 403 status code?

From Wikipedia,

A web server may return a 403 Forbidden HTTP status code in response to a request from a client for a web page or resource to indicate that the server can be reached and understood the request, but refuses to take any further action.

How to resolve error 403 while using Jsoup?

May of the websites filter web requests against the list of known user agents and denies access to unknown or bot user agents. Jsoup uses the Java version as a user agent string while making the request which could fall into the later category of bots and that could be the reason to get the 403 error – access is forbidden.

Simple solution to this problem is to specify user agent string while connecting to the website using Jsoup as given below.

Still getting Jsoup 403 error? Other possible causes of getting 403 error – access is forbidden is given below.

1) Specify HTTP referrer while making request using Jsoup.
2) If you are crawling the web too fast, website’s firewall may block you IP. Wait for few milliseconds before making next request using Thread.sleep method.

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


About the author



rahimv has over 15 years of experience in designing and developing Java applications. His areas of expertise are J2EE and eCommerce. If you like the website, follow him on Facebook, Twitter or Google Plus.

Add Comment

Your email address will not be published. Required fields are marked *