This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JSP and the fly likes java.io.IOException: Server returned HTTP response code: 401 for URL: Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "java.io.IOException: Server returned HTTP response code: 401 for URL:" Watch "java.io.IOException: Server returned HTTP response code: 401 for URL:" New topic
Author

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

Raihan Jamal
Ranch Hand

Joined: Mar 23, 2010
Posts: 86
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
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

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

Joined: Mar 23, 2010
Posts: 86
@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
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

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

Joined: Mar 23, 2010
Posts: 86
@Paul Clapham ,so that means authentication should be in proxy.jsp page right?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

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


Exactly!
Raihan Jamal
Ranch Hand

Joined: Mar 23, 2010
Posts: 86
I added the authentication code in proxy.jsp.. But I am getting MyAuthenticator cannot be resolved to a type.




Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

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

Joined: Mar 23, 2010
Posts: 86
@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
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

An example of what? All the code you need is there, just put it into the doGet() method of your servlet.
 
wood burning stoves
 
subject: java.io.IOException: Server returned HTTP response code: 401 for URL:
 
Similar Threads
calling web site
another question form Poddar's questions
Change Yahoo! Id ?
Invalid property in <set>
White spaces are required between publicId and systemId.