• 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
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

java.io.IOException: Server returned HTTP response code: 401 for URL:

 
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to make a ajax call to other domain locally from my computer by writing some proxy code in jsp. And this is my jQuery AJAX code that is calling proxy.jsp page. And I have also modified the request header for the cookie part.



And my JSP file is:-





And when I get the response back from the server. I get this error. Any idea why I am getting this error back..





Any suggestions will be appreciated..
 
Sheriff
Posts: 26777
82
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HTTP response code 401 means you didn't authenticate the request properly. (As you could easily have found out with at most 30 seconds of web searching.) So presumably that web site requires authentication.
 
Raihan Jamal
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@Paul Clapham, so how do I provide authentication... that is the part I am not able to understand.. And where i have to provide the authentication...
 
Paul Clapham
Sheriff
Posts: 26777
82
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Raihan Jamal wrote:@Paul Clapham, so how do I provide authentication...


Good Google keywords for this question would be "java http authentication". Try it, you'll like it.

And where i have to provide the authentication...


You provide the authentication at the time and place where you make the connection.
 
Raihan Jamal
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@Paul Clapham ,so that means authentication should be in proxy.jsp page right?
 
Paul Clapham
Sheriff
Posts: 26777
82
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Raihan Jamal wrote:@Paul Clapham ,so that means authentication should be in proxy.jsp page right?



Exactly!
 
Raihan Jamal
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I added the authentication code in proxy.jsp.. But I am getting MyAuthenticator cannot be resolved to a type.




 
Paul Clapham
Sheriff
Posts: 26777
82
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But why is that code even in a JSP? It's bad enough that you have a whole lump of Java code in a scriptlet, but presumably inner classes in that code lead to even more confusion. It's not worth figuring out why, just put the code in a servlet where it belongs.
 
Raihan Jamal
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@Paul Clapham, thanks for replying back.. Can you provide example based on my jsp code how to do this.. That will be of great help for me.. Frankly speaking I am not sure how to do this..
 
Paul Clapham
Sheriff
Posts: 26777
82
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
An example of what? All the code you need is there, just put it into the doGet() method of your servlet.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic