File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Sockets and Internet Protocols and the fly likes Having problem posting to Https. Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Reply Bookmark "Having problem posting to Https." Watch "Having problem posting to Https." New topic
Author

Having problem posting to Https.

Dave Trower
Ranch Hand

Joined: Feb 12, 2003
Posts: 78
I am having trouble posting XML to an https address.
The code I cam using works about 90% of the time, but it fails 10%.
Here is the code:
java.io.DataInputStream dis = null;
javax.net.ssl.HttpsURLConnection httpsCon = null;
java.net.URL url = new java.net.URL(address);
java.io.OutputStream reply = null;
java.io.FileInputStream requestToSend = null;
httpsCon = (javax.net.ssl.HttpsURLConnection) url.openConnection();
httpsCon.setHostnameVerifier(new javax.net.ssl.HostnameVerifier()
{
public boolean verify(String hostname, javax.net.ssl.SSLSession session) {
return true;
}
});
httpsCon.setDoOutput(true);
if(soapAction != null) {
httpsCon.setRequestProperty("SOAPAction", soapAction);
}
httpsCon.connect();
reply = httpsCon.getOutputStream();
requestToSend = new java.io.FileInputStream(requestXML);
int byteLength = requestToSend.available();
byte[] data = new byte[byteLength];
requestToSend.read(data);
reply.write(data);
dis = new java.io.DataInputStream(httpsCon.getInputStream());

That last line it blows up with the error:
Server returned HTTP response code: 500.

I don't think the problem is with the server I am connecting.
This code works most of the time.
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8259

Originally posted by Dave Trower:


That last line it blows up with the error:
Server returned HTTP response code: 500.

I don't think the problem is with the server I am connecting.
This code works most of the time.


Since the response code "500" is the http status code for an "internal server error", I'd say the problem isn't in the code you've shown us. It could be with the data you are sending, but without looking at the server code and logs I don't think we have enough information to help you at this point.


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Having problem posting to Https.
 
Similar Threads
Getting error while posting HTTPS POST method
Https post method
JSSE Problem
HTML/Post java.lang.classcastexception
"Corrupt GZIP Trailer"?