- From: Laird, Brian <BLaird@perseco.com>
- Date: Fri, 18 Jun 2004 11:46:09 -0500
- To: "Grigorios Merenidis" <grego501@gmx.net>, <www-jigsaw@w3.org>
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. ************************************************************************
Received on Friday, 18 June 2004 12:46:56 UTC