Exception thrown in Http POST sample code

Y

Young Cho

Hi,

I am trying to figure out how the Http POST works in .Net CF by using the
example in the MS book - .Net Compact Framework. However, I get the
following exception thrown when I compile the sample code from the book:

An unhandled exception of type 'System.Net.Sockets.SocketException' occurred
in System.dll
Additional information: A blocking operation is currently executing

I am trying to run on a PPC 2003 Emulator in the .Net VS 2003. No SPs on
the emulator. The code from the .Net Compact Framework book is below and
the exception is thrown on the requestStream.Close(); line.

Any thoughts or suggestions? Thanks!

Young.

string url = https://{my server URL};

string postData = "{my POST data - XML}";

WebRequest req = WebRequest.Create(url);

req.Method = "POST";

req.ContentType = "text/plain; charset=utf-8";

// Encode the data

byte[] encodedBytes = Encoding.UTF8.GetBytes(postData);

req.ContentLength = encodedBytes.Length;

// Write encoded data into request stream

Stream requestStream = req.GetRequestStream();

requestStream.Write(encodedBytes, 0, encodedBytes.Length);

requestStream.Close();

WebResponse result = req.GetResponse();
 
M

Mike Boilen [MS]

This is a bug in the .net CF. It happens because of a limitation in the
underlying SSL implementation on Windows CE. However, there is a work
around. If you set req.AllowWriteStreamBuffering to true, and do not set
req.ContentLength, you'll stop seeing the exception.

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: Exception thrown in Http POST sample code
| Date: Wed, 24 Sep 2003 09:12:00 -0700
| Lines: 45
| 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!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP12.phx.gbl
| Xref: cpmsftngxa06.phx.gbl
microsoft.public.dotnet.framework.compactframework:34335
| X-Tomcat-NG: microsoft.public.dotnet.framework.compactframework
|
| Hi,
|
| I am trying to figure out how the Http POST works in .Net CF by using the
| example in the MS book - .Net Compact Framework. However, I get the
| following exception thrown when I compile the sample code from the book:
|
| An unhandled exception of type 'System.Net.Sockets.SocketException'
occurred
| in System.dll
| Additional information: A blocking operation is currently executing
|
| I am trying to run on a PPC 2003 Emulator in the .Net VS 2003. No SPs on
| the emulator. The code from the .Net Compact Framework book is below and
| the exception is thrown on the requestStream.Close(); line.
|
| Any thoughts or suggestions? Thanks!
|
| Young.
|
| string url = https://{my server URL};
|
| string postData = "{my POST data - XML}";
|
| WebRequest req = WebRequest.Create(url);
|
| req.Method = "POST";
|
| req.ContentType = "text/plain; charset=utf-8";
|
| // Encode the data
|
| byte[] encodedBytes = Encoding.UTF8.GetBytes(postData);
|
| req.ContentLength = encodedBytes.Length;
|
| // Write encoded data into request stream
|
| Stream requestStream = req.GetRequestStream();
|
| requestStream.Write(encodedBytes, 0, encodedBytes.Length);
|
| requestStream.Close();
|
| WebResponse result = req.GetResponse();
|
|
|
 

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