Thank for help, sadly is not enogh.
I want to upload several files using MultipartPostMethod, the problem is
I'm redirected from the upload servlet back to the login form page.
Basicaly I want my client to authorize itself and than go the
UploadServlet to send the file to it.
Here is my addition(BOLDED) to the FormLoginDemo.java file.
...
if ((statuscode == HttpStatus.SC_MOVED_TEMPORARILY) ||
(statuscode == HttpStatus.SC_MOVED_PERMANENTLY) ||
(statuscode == HttpStatus.SC_SEE_OTHER) ||
(statuscode == HttpStatus.SC_TEMPORARY_REDIRECT)) {
Header header = authpost.getResponseHeader("location");
if (header != null) {
String newuri = header.getValue();
if ((newuri == null) || (newuri.equals(""))) {
newuri = "/";
}
System.out.println("Redirect target: " + newuri);
GetMethod redirect = new GetMethod(newuri);
client.executeMethod(redirect);
System.out.println("Redirect: " +
redirect.getStatusLine().toString());
// release any connection resources used by the method
redirect.releaseConnection();
File file=new File("c:\\Books\\<my file>");
MultipartPostMethod mPost = new MultipartPostMethod(
"http://localhost/MyApp/UploadServlet");
mPost.addParameter(file.getName(),file);
mPost.setFollowRedirects(true);
client.executeMethod(mPost);
System.out.println("Post status: " +
mPost.getStatusLine().toString());
mPost.releaseConnection();
} else {
System.out.println("Invalid redirect");
System.exit(1);
}
}
.........
And here are the logs for multipart request part:
2004/09/07 16:46:14:922 EEST [INFO] HttpMethodDirector - Redirect
requested but followRedirects is disabledLogin form post: HTTP/1.1 302
Found
Logon cookies:
- JSESSIONID=0000SdkoAaLYJd1wXxn-19q17Fe:-1
Redirect target: http://localhost:9080/InfoprintJobTicketer/login.html
2004/09/07 16:46:14:922 EEST [DEBUG] HttpMethodBase - Resorting to
protocol version default close connection policy
2004/09/07 16:46:14:922 EEST [DEBUG] HttpMethodBase - Should NOT close
connection, using HTTP/1.1
2004/09/07 16:46:14:922 EEST [DEBUG] HttpConnection - Releasing connection
back to connection manager.
Redirect: HTTP/1.1 200 OK
2004/09/07 16:46:14:922 EEST [DEBUG] HttpMethodBase - Adding Host request
header
2004/09/07 16:46:14:938 EEST [DEBUG] HttpMethodBase - Resorting to
protocol version default close connection policy
2004/09/07 16:46:14:938 EEST [DEBUG] HttpMethodBase - Should NOT close
connection, using HTTP/1.1
2004/09/07 16:46:14:938 EEST [DEBUG] HttpConnection - Releasing connection
back to connection manager.
2004/09/07 16:46:14:953 EEST [DEBUG] HttpMethodBase - Adding Host request
header
2004/09/07 16:46:16:250 EEST [DEBUG] HttpMethodDirector - Redirect
required
2004/09/07 16:46:16:250 EEST [DEBUG] HttpMethodDirector - Redirect
requested to location
'http://localhost:9080/InfoprintJobTicketer/login.html'
2004/09/07 16:46:16:250 EEST [DEBUG] HttpMethodDirector - Redirecting from
'http://localhost/MyApp/UploadServlet' to 'http://localhost/MyApp/
login.html
2004/09/07 16:46:16:250 EEST [DEBUG] HttpMethodDirector - Execute redirect
1 of 100
2004/09/07 16:46:16:250 EEST [DEBUG] HttpMethodBase - Resorting to
protocol version default close connection policy
2004/09/07 16:46:16:250 EEST [DEBUG] HttpMethodBase - Should NOT close
connection, using HTTP/1.1
2004/09/07 16:46:16:250 EEST [DEBUG] HttpConnection - Connection is
locked. Call to releaseConnection() ignored.
2004/09/07 16:46:16:266 EEST [DEBUG] HttpMethodBase - Adding Host request
header
2004/09/07 16:46:17:109 EEST [DEBUG] HttpMethodBase - Resorting to
protocol version default close connection policy
2004/09/07 16:46:17:109 EEST [DEBUG] HttpMethodBase - Should NOT close
connection, using HTTP/1.1
2004/09/07 16:46:17:109 EEST [DEBUG] HttpConnection - Releasing connection
back to connection manager.
Post status: HTTP/1.1 200 OK
[EMAIL PROTECTED]
09/07/2004 03:57 PM
Please respond to
"Jakarta Commons Users List" <[EMAIL PROTECTED]>
To
"Jakarta Commons Users List" <[EMAIL PROTECTED]>
cc
Subject
RE: [HttpClient] How to use HttpClient with Form-based Authentication?
Hope this one will do
http://cvs.apache.org/viewcvs.cgi/jakarta-commons/httpclient/src/examples/FormLoginDemo.java?view=markup
Oleg
>-- Original Message --
>Reply-To: "Jakarta Commons Users List" <[EMAIL PROTECTED]>
>To: [EMAIL PROTECTED]
>Subject: [HttpClient] How to use HttpClient with Form-based
Authentication?
>From: [EMAIL PROTECTED]
>Date: Tue, 7 Sep 2004 15:50:02 +0300
>
>
>Hi,
>
>Can HttpClient be used with Form-based Authentication?
>If yes can I have a code example?
>Thank you
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]