I have an application (web1) which needs to make requests to another
application(web2) and am using HttpClient BasicAuthentication to do this.
After logging in web1's webpage, here I need to access web2 using
HttpClient.
Since this http access happens from web1 to web2, it needs authentication.
So, I used BasicAuthentication with username and password to login to web2.
But instead of displaying the requested page , it always redirected to web2
login page(login.jsp).
Any solutions?
Here is the code I tried:
HttpClient client = new HttpClient();
client.getState().setCredentials(
new AuthScope("localhost", 8080),
new UsernamePasswordCredentials("test", "test"));
String url = "http://localhost:8080/web2/test.htm?action=getRecords";
GetMethod method = new GetMethod(url);
method.setDoAuthentication(true);
method.setFollowRedirects(true);
try {
int statusCode = client.executeMethod(method);
if (statusCode != HttpStatus.SC_OK) {
System.err.println("Method failed: " + method.getStatusLine());
}
// Read the response body.
byte[] responseBody = method.getResponseBody();
// Deal with the response.
// Use caution: ensure correct character encoding and is not binary data
System.out.println(new String(responseBody));
} catch (HttpException e) {
System.err.println("Fatal protocol violation: " + e.getMessage());
e.printStackTrace();
} catch (IOException e) {
System.err.println("Fatal transport error: " + e.getMessage());
e.printStackTrace();
} finally {
// Release the connection.
method.releaseConnection();
}
}
--
View this message in context:
http://old.nabble.com/Unable-to-access-from-one-web-app-to-another-web-app-using-HttpClient-BasicAuthentication-tp28922584p28922584.html
Sent from the HttpClient-User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]