0

For many web sites monitoring in developer console the network traffic, reveals transformation of text files which are virtually JSON's.

But when I trying to fetch this data via code, for some web sites I get:

  1. Status 403
  2. The text inside the file is not the expected JSON, rather error message.

What can be wrong? From the code point of view - it seems OK, the URL is correct (copy paste to browser works fine) and the code executes fine.

For me it seems that the URL is working OK within browser but not from code.

Code for example (java): simplest way to read json from a URL in java

Community
  • 1
  • 1
michael
  • 3,835
  • 14
  • 53
  • 90

1 Answers1

1

There are multiple reasons why this could happen.

  1. HTTP 403 means that you are authenticated but that the user you are using does not have the right privileges...
  2. It could also be that you are not sending the exact same HTTP headers from the browser and from your client. Inspect the headers you send with the browser and replicate them in your code
  3. It could be that your browser automatically redirects to HTTPS and that your code does not. If the server only allows access via HTTPS then an HTTP access would not work (though I wouldn't expect to see 403)
David Brossard
  • 13,584
  • 6
  • 55
  • 88