- From: Grigorios Merenidis <grego501@gmx.net>
- Date: Fri, 23 Jul 2004 18:52:43 +0200 (MEST)
- To: www-jigsaw@w3.org
Hi All!
I try to login to the URL
below
http://www.portal.mercedes-benz.de/mb-portal/www/Home?category=HOME&context=NAV
but it doesn't work.
I get the folling reply.dump(System.out)
HTTP/1.1 302 Found
Cache-Control: no-cache="set-cookie,set-cookie2"
Date: Fri, 23 Jul 2004 16:21:32 GMT
Transfer-Encoding: chunked
Set-Cookie:
mb.tracking=0llct00gr1mkt3agsb;Domain=.portal.mercedes-benz.de;Expires=Mon,
23-Jul-2007 16:21:32 GMT;Path=/
Content-Language: en
Content-Type: text/html
Expires: Thu, 01 Dec 1994 16:00:00
GMT
Location:
http://www.portal.mercedes-benz.de/mb-portal/www/NoCookies;jsessionid=0001AKVEZQCC2B5GX1HGUEQCIMY:u4m31e9e
Server: IBM_HTTP_SERVER/1.3.19.3 Apache/1.3.20 (Unix)
Vary: User-Agent
X-Cocoon-Version: 2.0.2
My source looks like this:
HttpSetCookieList cookieList = null;
try
{
HttpManager manager = HttpManager.getManager();
manager.setMaxConnections(100);
Request server_request = manager.createRequest();
server_request.setMethod(HTTP.POST);
server_request.setURL(new URL("http://www.portal.mercedes-benz.de/"
+ "mb-portal/www/Home?category=HOME&context=NAV"));
server_request.setAllowUserInteraction(false);
server_request.setContentType(
MimeType.APPLICATION_X_WWW_FORM_URLENCODED);
server_request.setUserAgent("Mozilla/4.0");
server_request.removeHeader("keep-alive");
PipedOutputStream output_stream = new PipedOutputStream();
OutputStreamWriter writer = new OutputStreamWriter(output_stream);
PipedInputStream input_stream = new PipedInputStream(output_stream);
StringBuffer post_data = new StringBuffer();
post_data.append("userName");
post_data.append("=");
post_data.append(getUserName());
post_data.append("&");
post_data.append("passwd");
post_data.append("=");
post_data.append(getPassword());
writer.write(post_data.toString());
writer.flush();
writer.close();
server_request.setOutputStream(input_stream);
server_request.setContentLength(post_data.length());
Reply reply = manager.runRequest(server_request);
if (reply.getStatus() > 400)
{
throw new Exception("Received an unexpected reply status code ("
+ reply.getStatus() + ")");
}
cookieList = reply.getSetCookie();
if (reply.getStatus() == 302)
{
URL location = new URL(reply.getLocation());
server_request.setURL(location);
InputStream is = reply.getInputStream();
BufferedReader commandLine = new BufferedReader(new
InputStreamReader(is));
while(commandLine.readLine() != null){
String s = commandLine.readLine();
System.out.println(s);
}
Reply reply_2 = null;
try {
Request server_request_2 = manager.createRequest();
server_request_2.setMethod(HTTP.POST);
server_request_2.setURL(location);
server_request_2.setAllowUserInteraction(false);
server_request_2.setContentType(
MimeType.APPLICATION_X_WWW_FORM_URLENCODED);
server_request_2.setUserAgent("Mozilla/4.0");
server_request_2.removeHeader("keep-alive");
server_request_2.setSetCookie(cookieList);
PipedOutputStream output_stream_2 = new PipedOutputStream();
OutputStreamWriter writer_2 = new
OutputStreamWriter(output_stream_2);
PipedInputStream input_stream_2 = new
PipedInputStream(output_stream_2);
StringBuffer post_data_2 = new StringBuffer();
post_data_2.append("userName");
post_data_2.append("=");
post_data_2.append(getUserName());
post_data_2.append("&");
post_data_2.append("passwd");
post_data_2.append("=");
post_data_2.append(getPassword());
writer_2.write(post_data_2.toString());
writer_2.flush();
writer_2.close();
server_request_2.setOutputStream(input_stream_2);
server_request_2.setContentLength(post_data.length());
reply_2 = manager.runRequest(server_request_2);
reply_2.dump(System.out);
} catch (Exception ex) {
System.out.println(ex.getMessage() + reply_2.getStatus());
}
}
}catch(Exception ex){}
}
Do enyone know what I am doing wrong?
Thanks for any Help!!!!!
>
> Hi Brian!
>
> I appriciate your prompt response!
> I will figure out your example and then I will
> write back if I have any further questions.
>
> Thanks!
>
> Gregory
>
> >
> > Here is an example of how to do single sign on. This won't compile
> > because it has our own variables and stuff but it should help you out.
> > A few notes about things I saw in your code:
> > - I don't think you need the question mark at the beginning of the post
> > data.
> > - You need to do use the skipBody method unless you are returning the
> > info to the client. The skipBody sends the body of the reply from the
> > remote server into the bit bucket.
> > - I also think you need to set the MIME type in your request.
> >
> > Hope this helps,
> > Brian
> >
> >
> > HttpSetCookieList cookieList = null;
> > try
> > {
> > if (isTracingEnabled())
> >
> > getLogger().trace("LoginPagePostSignOnFilter.initialSignOn - performing
> > single sign on for session" + session.getProxySessionId());
> > //test
> > HttpManager manager = HttpManager.getManager();
> > manager.setMaxConnections(100);
> > org.w3c.www.protocol.http.Request server_request =
> > manager.createRequest();
> > server_request.setMethod(HTTP.POST);
> > server_request.setURL(new URL(getLoginURL()));
> > server_request.setAllowUserInteraction(false);
> >
> > server_request.setContentType(MimeType.APPLICATION_X_WWW_FORM_URLENCODED
> > );
> > server_request.setUserAgent(request.getUserAgent());
> >
> > server_request.removeHeader("keep-alive");
> >
> > // build the post data
> > PipedOutputStream output_stream = new PipedOutputStream();
> > OutputStreamWriter writer = new
> > OutputStreamWriter(output_stream);
> > PipedInputStream input_stream = new
> > PipedInputStream(output_stream);
> > StringBuffer post_data = new StringBuffer();
> > post_data.append(getUsernameField());
> > post_data.append("=");
> > post_data.append(session.getUserName());
> > post_data.append("&");
> > post_data.append(getPasswordField());
> > post_data.append("=");
> > post_data.append(getPassword());
> > String[] extraFields = getExtraFields();
> > if (extraFields != null)
> > {
> > for (int i = 0; i < extraFields.length; i++)
> > {
> > post_data.append("&");
> > post_data.append(extraFields[i]);
> > }
> > }
> > writer.write(post_data.toString());
> > writer.flush();
> > writer.close();
> > server_request.setOutputStream(input_stream);
> > //server_request.setOutputStream(new
> > StringBufferInputStream(post_data.toString()));
> > server_request.setContentLength(post_data.length());
> > //System.out.println("Request being sent to the backend
> > server:");
> > //request.dump(System.out);
> > Reply reply = manager.runRequest(server_request);
> > if (reply.getStatus() > 400)
> > {
> > getLogger().errlog("Received an unexpected reply status
> > code (" + reply.getStatus() + ")");
> > getLogger().sync();
> > throw new ServerSignOnException("Received an unexpected
> > reply status code (" + reply.getStatus() + ")");
> > }
> > //System.out.println("Reply returned to the backend
> > server:");
> > //reply.dump(System.out);
> > cookieList = reply.getSetCookie();
> > skipBody(reply);
> >
> >
> >
> >
> >
> > -----Original Message-----
> > From: Grigorios Merenidis [mailto:grego501@gmx.net]
> > Sent: Friday, June 18, 2004 5:49 AM
> > To: www-jigsaw@w3.org
> > Subject: Fwd: Try to Login
> >
> >
> > Hi all!
> >
> > I use the jigsaw api to login into a site.
> > But if I try to request the server I get
> > the following error:
> >
> > Unable to contact target server www.mercedes-benz.de:80 after 1 tries
> >
> > My sample code looks like this:
> >
> > Request request = manager.createRequest();
> > String postdata=?username=USER&password=PASSWORD&btnSubmit=anmelden";
> > request.setMethod("POST");
> > request.setOutputStream(new StringBufferInputStream(postdata));
> > request.setContentLength(postdata.length());
> > request.setURL(new URL("http://www.mercedes-benz.de/portal"));
> > request.setUserAgent(USER_AGENT);
> > try{
> > reply = manager.runRequest(request);
> > }catch(Exception ex){
> > System.out.println(ex.getMessage());
> > }
> >
> > What I am doing wrong?
> >
> > Thanks for any Help!!
> >
> > Cheers!
> >
> > Gregory
> >
> >
> >
> > --
> > +++ Jetzt WLAN-Router f|r alle DSL-Einsteiger und Wechsler +++
> > GMX DSL-Powertarife zudem 3 Monate gratis* http://www.gmx.net/dsl
> >
> >
> >
> > ************************************************************************
> > This e-mail and any accompanying documents or files contain information
> > that is the
> > property of Perseco, that is intended solely for those to whom this
> e-mail
> > is addressed
> > (i.e., those identified in the "To" and "Cc" boxes), and that is
> > confidential, proprietary,
> > and/or privileged. If you are not an intended recipient of this e-mail,
> > you are hereby
> > notified that any viewing, use, disclosure, forwarding, copying, or
> > distribution of any of
> > this information is strictly prohibited and may be subject to legal
> > sanctions. If you have
> > received this e-mail in error, please notify the sender immediately of
> any
> > unintended
> > recipients, and delete the e-mail, all attachments, and all copies of
> both
> > >from your system.
> >
> > While we have taken reasonable precautions to ensure that any
> attachments
> > to this e-mail
> > have been swept for viruses, we cannot accept liability for any damage
> > sustained as a
> > result of software viruses.
> > ************************************************************************
> >
>
> --
> "Sie haben neue Mails!" - Die GMX Toolbar informiert Sie beim Surfen!
> Jetzt aktivieren unter http://www.gmx.net/info
>
--
+++ GMX DSL-Tarife 3 Monate gratis* +++ Nur bis 25.7.2004 +++
Bis 24.000 MB oder 300 Freistunden inkl. http://www.gmx.net/de/go/dsl
--
+++ GMX DSL-Tarife 3 Monate gratis* +++ Nur bis 25.7.2004 +++
Bis 24.000 MB oder 300 Freistunden inkl. http://www.gmx.net/de/go/dsl
Received on Friday, 23 July 2004 12:53:16 UTC