HttpWebRequest.GetResponse() times out with SSL connections, but works with normal connection

D

Detlev Schwabe

Hello,

the following code excerpt throws a Timeout web exception IF:

a) the POST goes over an HTTPS connection, and
b) the POST content (the byte array) is of a certain size (probably a few
kilobytes)

Shorter content (<1024bytes) works fine and reach the server. But an array
of 30KB or larger never reach the server. The strange thing is that
everything works like expected if the connection is an ordinary HTTP.

No matter how large I set the timeout time, or whatever combination I choose
for ContentLength, AllowWriteStreamBuffering or SendChunked, it always fails
for byte arrays that are larger than a couple hundred bytes.

I'm using CF 2.0 on a Pocket PC 2003 2nd Ed. device. The script on the
server is a ASP.NET handler. The proper certificates for SSL have all been
installed on the device.

Anyone any ideas?
Any help is greatly appreciated!

-Detlev

-----------------------------------------------------------

private bool PostStream( byte[] buffer, string url )
{
Uri myUri = new Uri( url );

HttpWebRequest objRequest = ( HttpWebRequest )WebRequest.Create( myUri );
objRequest.Method = "POST";
objRequest.ContentType = "application/octet-stream";
objRequest.ContentLength = buffer.Length;
objRequest.AllowWriteStreamBuffering = true;

try
{
using( BinaryWriter wr = new BinaryWriter(
objRequest.GetRequestStream() ) )
{
wr.Write( buffer, 0, buffer.Length );
wr.Close();
}
}
catch( Exception )
{
return false;
}

try
{
HttpWebResponse objResponse = ( HttpWebResponse )objRequest.GetResponse();
using( StreamReader sr = new StreamReader(
objResponse.GetResponseStream() ) )
{
//...
}
}
catch( WebException )
{
// the timeout is caught here...
return false;
}
}
 
W

Will Chapman

Detlev said:
Hello,

the following code excerpt throws a Timeout web exception IF:
Detlev

Detlev said:
Hello,

the following code excerpt throws a Timeout web exception IF:

I don't know whther is will help but I've found that I have to declare
various headers to get HttpWebrequest to work consistently in
..NET CF v2, thus:

HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
req.Method = "Get";
req.ContentType = "text/plain";
req.UserAgent = "iPaq6515/.NETCF";
req.Accept = "*/*";
req.ProtocolVersion = HttpVersion.Version10;
req.Timeout = 5000;

HTH

Will CHapman




a) the POST goes over an HTTPS connection, and
b) the POST content (the byte array) is of a certain size (probably a
few kilobytes)

Shorter content (<1024bytes) works fine and reach the server. But an
array of 30KB or larger never reach the server. The strange thing is
that everything works like expected if the connection is an ordinary
HTTP.
No matter how large I set the timeout time, or whatever combination I
choose for ContentLength, AllowWriteStreamBuffering or SendChunked,
it always fails for byte arrays that are larger than a couple hundred
bytes.
I'm using CF 2.0 on a Pocket PC 2003 2nd Ed. device. The script on the
server is a ASP.NET handler. The proper certificates for SSL have all
been installed on the device.

Anyone any ideas?
Any help is greatly appreciated!

-Detlev

-----------------------------------------------------------

private bool PostStream( byte[] buffer, string url )
{
Uri myUri = new Uri( url );

HttpWebRequest objRequest = ( HttpWebRequest )WebRequest.Create(
myUri ); objRequest.Method = "POST";
objRequest.ContentType = "application/octet-stream";
objRequest.ContentLength = buffer.Length;
objRequest.AllowWriteStreamBuffering = true;

try
{
using( BinaryWriter wr = new BinaryWriter(
objRequest.GetRequestStream() ) )
{
wr.Write( buffer, 0, buffer.Length );
wr.Close();
}
}
catch( Exception )
{
return false;
}

try
{
HttpWebResponse objResponse = ( HttpWebResponse
)objRequest.GetResponse(); using( StreamReader sr = new StreamReader(
objResponse.GetResponseStream() ) )
{
//...
}
}
catch( WebException )
{
// the timeout is caught here...
return false;
}
}

--
Cheers.......


Will Chapman
nb Quidditch
 
D

Detlev Schwabe

I determined the exact data size where the timeout starts occuring. It's
exactly 16359 bytes.
16358 bytes will still go through fine. Adding to this the typical header
size it looks like
the "magical" power of two 16,384 number.
My assumption right now is that this seems to be the limit of the underlying
SSL encryption
on mobile devices. If that is correct I'm just surprised that I don't get
any other kind
of exception. Unfortunately I don't have a very deep understanding of the
Cryptography
module in .NET CF.

-Detlev
 

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