You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by "Lomvardias, Christopher" <cl...@syscom.com> on 2002/04/29 19:46:20 UTC
HttpClient and SSL problems?
Hi,
I'm having trouble using the HttpClient to post to an SSL server (running
Tomcat 4.01). I am able to post to a non SSL Tomcat server using the same
code (by modifying port and url). Wondering if anyone can shed some light on
the error that I'm getting.
Here is the error.
java.lang.IllegalStateException: Not Used.
at
org.apache.commons.httpclient.HttpMethodBase.checkUsed(HttpMethodBase.java:1
167)
Here is the code I'm using to do the post.
<%@ page session="false" import="java.io.*, java.net.*, javax.xml.*,
java.util.*,
java.security.*,
java.util.Properties,
java.security.cert.*,
org.apache.commons.httpclient.*,
org.apache.commons.httpclient.Header,
org.apache.commons.httpclient.HttpConnection,
org.apache.commons.httpclient.HttpState,
org.apache.commons.httpclient.methods.*,
org.apache.commons.httpclient.methods.PostMethod" %><%
System.setProperty("java.protocol.handler.pkgs","com.sun.net.ssl.internal.ww
w.protocol");
java.security.Security.addProvider(new
com.sun.net.ssl.internal.ssl.Provider());
int theport = 443;
URL xmlurl = new
URL("https://www.myserver.com:443/ABC/abcserver.jsp");
HttpConnection connection = new HttpConnection(xmlurl.getHost(),
xmlurl.getPort(), true);
try {
connection.open();
}
catch (Exception ex) {}
PostMethod method = new PostMethod(xmlurl.getFile()) {
protected String generateRequestBody(HashMap params)
{
try {
StringBuffer bodyBuffer
= new StringBuffer(super.generateRequestBody(params));
bodyBuffer.append("\n");
// Write the XML document from Output Stream
return xmlString;
}
catch (Exception ex) {
return null;
}
}
};
method.setRequestHeader(new Header("Content-type", "text/xml"));
method.setFollowRedirects(false);
method.setUseDisk(true);
HttpState state = new HttpState();
try {
method.execute(state,connection);
}
catch (Exception ex) {}
String str = method.getResponseBodyAsString();
if (method.getStatusCode() != 404) {
out.println(str);
}
else {
out.println(method.getStatusCode()+"<br>");
out.println(method.getStatusText()+"<br>");
out.println(method.getResponseHeaders()+"<br>");
out.println(method.getResponseHeaders().length+"<br>");
out.println(method.getResponseHeader("Content-type")+"<br>");
}
%>
Thanks,
Chris
------------------------------------------------------------------
Chris Lomvardias
clomvardias@syscom.com
PublicBuy.Net
400 E. Pratt Street, Suite 300
Baltimore, MD 21202
(410)539-3737 x1722 voice
(410)539-7302 fax
4439941549@mobile.att.net (pager via email)
------------------------------------------------------------------
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>