WebRequestMethods.Http.Post XML file on HTTPS

P

patrick bes

Hi,

I have a situation where i have to post an XML document to a thirdparty
application. We have used to following code for a couple of months now and
everything worked just fine. The URL I used was just http and no SSL was
used, but the thirdparty application now implemented SSL and now uses HTTPS.
When I change the URL to HTTPS i get the following exception on
request.GetResponse():

The underlying connection was closed: An unexpected error occurred on a send.
The handshake failed due to an unexpected packet format.

The code:
UriBuilder u = new UriBuilder(AUrl);
u.Port = APort;

WebRequest request = WebRequest.Create(u.Uri);
request.Method = WebRequestMethods.Http.Post;
request.ContentType = "text/xml";

Stream requestStream = request.GetRequestStream();
StreamWriter send = new StreamWriter(requestStream,
System.Text.Encoding.UTF8);
try
{
send.Write(ARequest);
}
finally
{
send.Close();
requestStream.Close();
}
response = request.GetResponse();
Stream responseStream = response.GetResponseStream();
reader = new StreamReader(responseStream);
return reader.ReadToEnd();

Can anyone shed some light on this error?
Thank you in advance.
 
V

Vadym Stetsiak

Hello, patrick!

What version of SSL remote peer is supporting now?

Just a hint try to connect to remote server using browser (Internet
Explorer) and report here the results.
Another way is to try to connect manually to that server just to verify that
everything is okay with SSL. This can be done
via SSLStream class (
http://msdn2.microsoft.com/en-us/library/system.net.security.sslstream.aspx
)

--
With best regards, Vadym Stetsiak.
Blog: http://vadmyst.blogspot.com


You wrote on Thu, 17 Jan 2008 07:52:01 -0800:

pb> Hi,

pb> I have a situation where i have to post an XML document to a
pb> thirdparty application. We have used to following code for a couple
pb> of months now and everything worked just fine. The URL I used was
pb> just http and no SSL was used, but the thirdparty application now
pb> implemented SSL and now uses HTTPS.
pb> When I change the URL to HTTPS i get the following exception on
pb> request.GetResponse():

pb> The underlying connection was closed: An unexpected error occurred
pb> on a send.
pb> The handshake failed due to an unexpected packet format.

pb> The code:
pb> UriBuilder u = new UriBuilder(AUrl);
pb> u.Port = APort;

pb> WebRequest request = WebRequest.Create(u.Uri);
pb> request.Method = WebRequestMethods.Http.Post;
pb> request.ContentType = "text/xml";

pb> Stream requestStream = request.GetRequestStream();
pb> StreamWriter send = new StreamWriter(requestStream,
pb> System.Text.Encoding.UTF8);
pb> try {
pb> send.Write(ARequest);
pb> }
pb> finally {
pb> send.Close();
pb> requestStream.Close();
pb> }
pb> response = request.GetResponse();
pb> Stream responseStream = response.GetResponseStream();
pb> reader = new StreamReader(responseStream);
pb> return reader.ReadToEnd();

pb> Can anyone shed some light on this error?
pb> Thank you in advance.
 
P

patrick bes

Hi Vadym,

Thanks for your reply. I used fiddler to scan the http and https requests
and came to the conclusion that the thirdparty application required a custom
header element to post data. After adding this header element every things
seems to be working fine.

Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top