2

I want to connect https url using Jsoup I followed How to connect via HTTPS using Jsoup??

But now I am getting

Exception in thread "main" org.jsoup.HttpStatusException: HTTP error fetching URL. Status=401, URL=myurl
    at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:435)
    at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:410)
    at org.jsoup.helper.HttpConnection.execute(HttpConnection.java:164)
    at org.jsoup.helper.HttpConnection.get(HttpConnection.java:153)
    at FIndItNow.main(FIndItNow.java:27)

Any idea how to fix this ?

I am calling like

Document doc = Jsoup.connect(myurl).userAgent("Mozilla").get();
Junaid
  • 2,184
  • 4
  • 35
  • 66
abhig
  • 740
  • 1
  • 10
  • 22

1 Answers1

3

As error 401 says it is an UNAUTHORIZED request. It seems you need send some authentication headers in the request. Either you are not sending them or those are not correct.

Juned Ahsan
  • 63,914
  • 9
  • 87
  • 123
  • Any idea about code what should I do to send authentication headers? – abhig Jun 20 '13 at 18:12
  • @abhig That depends on what kind of authentication server has put in place. If it is Basic authentication, then the header is like this: WWW-Authenticate: Basic realm="insert realm" – Juned Ahsan Jun 20 '13 at 22:57