Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Having problem posting to Https.

 
Dave Trower
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9338
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic