• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Raihan Jamal
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • 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..
 
Paul Clapham
Sheriff
Posts: 21111
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • 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
  • 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: 21111
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
@Paul Clapham ,so that means authentication should be in proxy.jsp page right?
 
Paul Clapham
Sheriff
Posts: 21111
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • 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
  • 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: 21111
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • 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
  • 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: 21111
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic