• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Httpclient - Getting http error 403 forbidden

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello folks,

I need to access a URL to retrieve a JSON result.

When I try to open in the browser it works:
1. I go to www.url.com/signin and enter username and password. It takes me to the home page
2. I go to www.url.com/json to get the JSON result and it works fine, I can see the JSON in the browser.

I'm trying to use the HTTPClient library version 4.1.3 to achieve the same result in my Java program. I am able to connect and I can see the JSESSIONID cookie recorded and it redirects to the home page. That works fine.
However when I try to access the JSON page it does not work as I get http error 403 - forbidden.

I have tried 3 different approaches, all of them failed. Do you guys know what I'm doing wrong? Thanks a million in advance!!!
1. Using HttpContext object and passing it to both the HttpGet used to signin and the HttpGet used to retrieve the JSON page.

2. Retrieving the JSESSIONID cookie, creating a new cookie with its value, adding it to a CookieStore and passing the CookieStore to the Httpclient object.

3. Using the code below, which seems to be the solution according to the HttpClient documentation:

 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic