- From: Laird, Brian <BLaird@perseco.com>
- Date: Thu, 20 Mar 2003 16:27:29 -0600
- To: <www-jigsaw@w3.org>
I found another post in the list archive which helped me. I needed to set the content type to be form encoded, and then everything was fine. server_request.setContentType(MimeType.APPLICATION_X_WWW_FORM_URLENCODED); Brian > -----Original Message----- > From: Laird, Brian > Sent: Thursday, March 20, 2003 2:48 PM > To: 'www-jigsaw@w3.org' > Subject: Using the HTTPManager to make a POST > > I am looking to perform a login to a remote server, so I have written a filter which performs the sign in and then sends the user their session cookies. The problem I am having is getting the POST data to be sent as a part of the original POST. According to the packet sniffer I have, the post data is being sent in a separate message as a HTTP Continue, but the backend server replies prior to getting the request formatted as the HTTP Continue. Below is my code snippet, if someone could let me know what I am doing wrong, I would really appreciate it. > > Thanks in advance for any help, > Brian > > > > HttpManager manager = HttpManager.getManager(); > 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.setCookie(request.getCookie()); > > // Update the client request fields: > Enumeration e = request.enumerateHeaderDescriptions(); > while ( e.hasMoreElements() ) { > HeaderDescription d = (HeaderDescription) e.nextElement(); > HeaderValue v = request.getHeaderValue(d); > if ( v != null ) > server_request.setHeaderValue(d, v); > } > > server_request.removeHeader("keep-alive"); > // By removing that HOST, we make sure the real Host header gets > // computed by the client side API > server_request.setHeaderValue(org.w3c.www.protocol.http.Request.H_HOST,null); > > // 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(username); > post_data.append("&"); > post_data.append(getPasswordField()); > post_data.append("="); > post_data.append(getPassword()); > writer.write(post_data.toString()); > writer.flush(); > // if I don't do this the runRequest never completes > writer.close(); > server_request.setOutputStream(input_stream); > Reply reply = manager.runRequest(server_request); > cookieList = reply.getCookie(); >
Received on Thursday, 20 March 2003 17:27:39 UTC