HttpWebRequest object POST operation via HTTPS (SSL) fails

Y

Young Cho

We are trying to hit an IBM web server (Apache-based I believe) via
HttpWebRequest POST method over SSL. The data that is being sent is an XML
package. The request returns the following exception:
An unhandled exception of type 'System.Net.Sockets.SocketException' occurred in System.dll
Additional information: A blocking operation is currently executing

The error seems to be in the requestStream.Write() operation. Furthermore,
the code works fine if we switch from HTTPS to HTTP. The test is being done
// Create the HTTP POST request and the authentication headers
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(https://www.myserver.com/testsite);
req.Method = "POST";
req.ContentType = "text/xml";
req.Headers.Add("Authorization: Basic " + authStr); // authStr contains base64 encoded string

byte[] encodedBytes = Encoding.UTF8.GetBytes(payload); // payload is XML string
req.ContentLength = encodedBytes.Length;

requestStream = req.GetRequestStream();
requestStream.Write(encodedBytes, 0 , encodedBytes.Length);
requestStream.Close();

result = (HttpWebResponse)req.GetResponse();
receiveStream = result.GetResponseStream();

StreamReader sr = new StreamReader( receiveStream );
resultstring = sr.ReadToEnd();

Finally, when we were fiddling on the web server, we changed the cipher on
the web server from RC4-MD5 to RC4-SHA. That also seems to allow us to get
further over HTTPS. I don't think the SSL cipher on the HttpWebRequest
object is something we can change...

Any thoughts or suggestions would be appreciated. Thank you!

Young.
 
M

Mike Boilen [MS]

There is a bug in http client that is exposed by the code you are using.
Instead of setting req.ContentLength, you should set
AllowWriteStreamBuffering to true. This will work around the problem you
have.

Sorry for the inconvenience.

Mike Boilen
Developer
NET Compact Framework

This posting is provided "AS IS" with no warranties, and confers no rights.
http://www.gotdotnet.com/team/netcf/FAQ.aspx

--------------------
| From: "Young Cho" <[email protected]>
| Subject: HttpWebRequest object POST operation via HTTPS (SSL) fails
| Date: Thu, 23 Oct 2003 09:54:08 -0700
| Lines: 46
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.compactframework
| NNTP-Posting-Host: ycho.qualcomm.com 129.46.148.47
| Path:
cpmsftngxa06.phx.gbl!cpmsftngxa10.phx.gbl!TK2MSFTNGXA05.phx.gbl!TK2MSFTNGP08
phx.gbl!tk2msftngp13.phx.gbl
| Xref: cpmsftngxa06.phx.gbl
microsoft.public.dotnet.framework.compactframework:36713
| X-Tomcat-NG: microsoft.public.dotnet.framework.compactframework
|
| We are trying to hit an IBM web server (Apache-based I believe) via
| HttpWebRequest POST method over SSL. The data that is being sent is an
XML
| package. The request returns the following exception:
|
| > An unhandled exception of type 'System.Net.Sockets.SocketException'
| occurred in System.dll
| > Additional information: A blocking operation is currently executing
|
| The error seems to be in the requestStream.Write() operation.
Furthermore,
| the code works fine if we switch from HTTPS to HTTP. The test is being
done
| on VS .Net 2003 and the PPC 2003 emulator. The source code for the POST
is
| given below:
|
| > // Create the HTTP POST request and the authentication headers
| > HttpWebRequest req =
| (HttpWebRequest)WebRequest.Create(https://www.myserver.com/testsite);
| > req.Method = "POST";
| > req.ContentType = "text/xml";
| > req.Headers.Add("Authorization: Basic " + authStr); // authStr
| contains base64 encoded string
| >
| > byte[] encodedBytes = Encoding.UTF8.GetBytes(payload); // payload is
| XML string
| > req.ContentLength = encodedBytes.Length;
| >
| > requestStream = req.GetRequestStream();
| > requestStream.Write(encodedBytes, 0 , encodedBytes.Length);
| > requestStream.Close();
| >
| > result = (HttpWebResponse)req.GetResponse();
| > receiveStream = result.GetResponseStream();
| >
| > StreamReader sr = new StreamReader( receiveStream );
| > resultstring = sr.ReadToEnd();
|
| Finally, when we were fiddling on the web server, we changed the cipher on
| the web server from RC4-MD5 to RC4-SHA. That also seems to allow us to
get
| further over HTTPS. I don't think the SSL cipher on the HttpWebRequest
| object is something we can change...
|
| Any thoughts or suggestions would be appreciated. Thank you!
|
| Young.
|
|
|
|
 

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