SP2 Problems with HttpWebRequest.GetResponse()

O

Ofer B.

Hi all
I had some code that works fine till the SP2.
I try to download a file from the internet.
after the sp2 I get "WebExeption" for this line: response =
(HttpWebResponse)request.GetResponse();

do any body know how to solve it?

this is the all function
---------------------------------------------------------------------------
/// <summary>
/// connect to an internet link, download data, and save it to a file.
/// </summary>
private void DownloadData(string link, string file)
{
HttpWebRequest request;
HttpWebResponse response;
Stream ReceiveStream = null;
FileStream fstr = null;
try
{
request = (HttpWebRequest)WebRequest.Create(link);
request.Credentials = new NetworkCredential(this.txtUserName.Text ,
this.txtUserPass.Text);
response = (HttpWebResponse)request.GetResponse();
ReceiveStream = response.GetResponseStream();
// Now read s into a byte buffer.
byte[] bytes = new byte[100000];
int numBytesToRead = (int)bytes.Length;
int numBytesRead = 0;
while (numBytesToRead > 0)
{
// Read may return anything from 0 to numBytesToRead.
int n = ReceiveStream.Read(bytes, numBytesRead, numBytesToRead);
// The end of the file is reached.
if (n==0)
break;
numBytesRead += n;
numBytesToRead -= n;
}
ReceiveStream.Close();
// numBytesToRead should be 0 now

fstr = new FileStream(file, FileMode.OpenOrCreate,FileAccess.Write);
fstr.Write(bytes, 0, numBytesRead);
fstr.Close();
}
catch(WebException we)
{
throw we;
}
catch(Exception ex)
{
throw ex;
}
finally
{
request = null;
response = null;
}
}
 
A

Alex Feinman [MVP]

Could you provide the complete contents of the WebException (call
..ToString() on it)?
 
C

Chris Theorin

This is happening to me too. A ToString() on the exception object yields
only:

"System.Net.WebException:WebException"

A .Status.ToString() on the WebException object yields:

"ConnectFailure"



Simply uninstall SP2 (use "bare" (no SP) .NET CF in ROM) and run and works
fine...



Alex Feinman said:
Could you provide the complete contents of the WebException (call
.ToString() on it)?


Ofer B. said:
Hi all
I had some code that works fine till the SP2.
I try to download a file from the internet.
after the sp2 I get "WebExeption" for this line: response =
(HttpWebResponse)request.GetResponse();

do any body know how to solve it?

this is the all function
--------------------------------------------------------------------------
-
/// <summary>
/// connect to an internet link, download data, and save it to a file.
/// </summary>
private void DownloadData(string link, string file)
{
HttpWebRequest request;
HttpWebResponse response;
Stream ReceiveStream = null;
FileStream fstr = null;
try
{
request = (HttpWebRequest)WebRequest.Create(link);
request.Credentials = new NetworkCredential(this.txtUserName.Text ,
this.txtUserPass.Text);
response = (HttpWebResponse)request.GetResponse();
ReceiveStream = response.GetResponseStream();
// Now read s into a byte buffer.
byte[] bytes = new byte[100000];
int numBytesToRead = (int)bytes.Length;
int numBytesRead = 0;
while (numBytesToRead > 0)
{
// Read may return anything from 0 to numBytesToRead.
int n = ReceiveStream.Read(bytes, numBytesRead, numBytesToRead);
// The end of the file is reached.
if (n==0)
break;
numBytesRead += n;
numBytesToRead -= n;
}
ReceiveStream.Close();
// numBytesToRead should be 0 now

fstr = new FileStream(file, FileMode.OpenOrCreate,FileAccess.Write);
fstr.Write(bytes, 0, numBytesRead);
fstr.Close();
}
catch(WebException we)
{
throw we;
}
catch(Exception ex)
{
throw ex;
}
finally
{
request = null;
response = null;
}
}
 
A

Alex Feinman [MVP]

Chris,

I've just retested on iPaq with SP2 my sample
(http://www.alexfeinman.com/download.asp?doc=FileDownload.zip)
It seems to work fine. Could you try it on your device and in case you are
doing it differently, could you let me know what else should I try?

Alex

Chris Theorin said:
This is happening to me too. A ToString() on the exception object yields
only:

"System.Net.WebException:WebException"

A .Status.ToString() on the WebException object yields:

"ConnectFailure"



Simply uninstall SP2 (use "bare" (no SP) .NET CF in ROM) and run and works
fine...



Alex Feinman said:
Could you provide the complete contents of the WebException (call
.ToString() on it)?


Ofer B. said:
Hi all
I had some code that works fine till the SP2.
I try to download a file from the internet.
after the sp2 I get "WebExeption" for this line: response =
(HttpWebResponse)request.GetResponse();

do any body know how to solve it?

this is the all function

--------------------------------------------------------------------------
-
/// <summary>
/// connect to an internet link, download data, and save it to a file.
/// </summary>
private void DownloadData(string link, string file)
{
HttpWebRequest request;
HttpWebResponse response;
Stream ReceiveStream = null;
FileStream fstr = null;
try
{
request = (HttpWebRequest)WebRequest.Create(link);
request.Credentials = new NetworkCredential(this.txtUserName.Text ,
this.txtUserPass.Text);
response = (HttpWebResponse)request.GetResponse();
ReceiveStream = response.GetResponseStream();
// Now read s into a byte buffer.
byte[] bytes = new byte[100000];
int numBytesToRead = (int)bytes.Length;
int numBytesRead = 0;
while (numBytesToRead > 0)
{
// Read may return anything from 0 to numBytesToRead.
int n = ReceiveStream.Read(bytes, numBytesRead, numBytesToRead);
// The end of the file is reached.
if (n==0)
break;
numBytesRead += n;
numBytesToRead -= n;
}
ReceiveStream.Close();
// numBytesToRead should be 0 now

fstr = new FileStream(file, FileMode.OpenOrCreate,FileAccess.Write);
fstr.Write(bytes, 0, numBytesRead);
fstr.Close();
}
catch(WebException we)
{
throw we;
}
catch(Exception ex)
{
throw ex;
}
finally
{
request = null;
response = null;
}
}
 
C

Chris Theorin

I sent a response this morning but haven't seen it "show up" yet... The
sample worked, I'm trying to give you a sample that doesn't now :) D

Alex Feinman said:
Chris,

I've just retested on iPaq with SP2 my sample
(http://www.alexfeinman.com/download.asp?doc=FileDownload.zip)
It seems to work fine. Could you try it on your device and in case you are
doing it differently, could you let me know what else should I try?

Alex

Chris Theorin said:
This is happening to me too. A ToString() on the exception object yields
only:

"System.Net.WebException:WebException"

A .Status.ToString() on the WebException object yields:

"ConnectFailure"



Simply uninstall SP2 (use "bare" (no SP) .NET CF in ROM) and run and works
fine...



Alex Feinman said:
Could you provide the complete contents of the WebException (call
.ToString() on it)?


Hi all
I had some code that works fine till the SP2.
I try to download a file from the internet.
after the sp2 I get "WebExeption" for this line: response =
(HttpWebResponse)request.GetResponse();

do any body know how to solve it?

this is the all function

--------------------------------------------------------------------------
-
/// <summary>
/// connect to an internet link, download data, and save it to a file.
/// </summary>
private void DownloadData(string link, string file)
{
HttpWebRequest request;
HttpWebResponse response;
Stream ReceiveStream = null;
FileStream fstr = null;
try
{
request = (HttpWebRequest)WebRequest.Create(link);
request.Credentials = new NetworkCredential(this.txtUserName.Text ,
this.txtUserPass.Text);
response = (HttpWebResponse)request.GetResponse();
ReceiveStream = response.GetResponseStream();
// Now read s into a byte buffer.
byte[] bytes = new byte[100000];
int numBytesToRead = (int)bytes.Length;
int numBytesRead = 0;
while (numBytesToRead > 0)
{
// Read may return anything from 0 to numBytesToRead.
int n = ReceiveStream.Read(bytes, numBytesRead, numBytesToRead);
// The end of the file is reached.
if (n==0)
break;
numBytesRead += n;
numBytesToRead -= n;
}
ReceiveStream.Close();
// numBytesToRead should be 0 now

fstr = new FileStream(file, FileMode.OpenOrCreate,FileAccess.Write);
fstr.Write(bytes, 0, numBytesRead);
fstr.Close();
}
catch(WebException we)
{
throw we;
}
catch(Exception ex)
{
throw ex;
}
finally
{
request = null;
response = null;
}
}
 
C

Chris Theorin

Alex... can you do a sample with a "POST" instead of a "GET" and see if it
still works for you? As far as I can tell the "GET" is working just fine.

Alex Feinman said:
Chris,

I've just retested on iPaq with SP2 my sample
(http://www.alexfeinman.com/download.asp?doc=FileDownload.zip)
It seems to work fine. Could you try it on your device and in case you are
doing it differently, could you let me know what else should I try?

Alex

Chris Theorin said:
This is happening to me too. A ToString() on the exception object yields
only:

"System.Net.WebException:WebException"

A .Status.ToString() on the WebException object yields:

"ConnectFailure"



Simply uninstall SP2 (use "bare" (no SP) .NET CF in ROM) and run and works
fine...



Alex Feinman said:
Could you provide the complete contents of the WebException (call
.ToString() on it)?


Hi all
I had some code that works fine till the SP2.
I try to download a file from the internet.
after the sp2 I get "WebExeption" for this line: response =
(HttpWebResponse)request.GetResponse();

do any body know how to solve it?

this is the all function

--------------------------------------------------------------------------
-
/// <summary>
/// connect to an internet link, download data, and save it to a file.
/// </summary>
private void DownloadData(string link, string file)
{
HttpWebRequest request;
HttpWebResponse response;
Stream ReceiveStream = null;
FileStream fstr = null;
try
{
request = (HttpWebRequest)WebRequest.Create(link);
request.Credentials = new NetworkCredential(this.txtUserName.Text ,
this.txtUserPass.Text);
response = (HttpWebResponse)request.GetResponse();
ReceiveStream = response.GetResponseStream();
// Now read s into a byte buffer.
byte[] bytes = new byte[100000];
int numBytesToRead = (int)bytes.Length;
int numBytesRead = 0;
while (numBytesToRead > 0)
{
// Read may return anything from 0 to numBytesToRead.
int n = ReceiveStream.Read(bytes, numBytesRead, numBytesToRead);
// The end of the file is reached.
if (n==0)
break;
numBytesRead += n;
numBytesToRead -= n;
}
ReceiveStream.Close();
// numBytesToRead should be 0 now

fstr = new FileStream(file, FileMode.OpenOrCreate,FileAccess.Write);
fstr.Write(bytes, 0, numBytesRead);
fstr.Close();
}
catch(WebException we)
{
throw we;
}
catch(Exception ex)
{
throw ex;
}
finally
{
request = null;
response = null;
}
}
 
A

Alex Feinman [MVP]

Still works. I've updated the sample at
http://www.alexfeinman.com/download.asp?doc=FileDownload.zip so that now you
can choose the request method. Let me know.

Alex

Chris Theorin said:
Alex... can you do a sample with a "POST" instead of a "GET" and see if it
still works for you? As far as I can tell the "GET" is working just fine.

Alex Feinman said:
Chris,

I've just retested on iPaq with SP2 my sample
(http://www.alexfeinman.com/download.asp?doc=FileDownload.zip)
It seems to work fine. Could you try it on your device and in case you are
doing it differently, could you let me know what else should I try?

Alex

Chris Theorin said:
This is happening to me too. A ToString() on the exception object yields
only:

"System.Net.WebException:WebException"

A .Status.ToString() on the WebException object yields:

"ConnectFailure"



Simply uninstall SP2 (use "bare" (no SP) .NET CF in ROM) and run and works
fine...



Could you provide the complete contents of the WebException (call
.ToString() on it)?


Hi all
I had some code that works fine till the SP2.
I try to download a file from the internet.
after the sp2 I get "WebExeption" for this line: response =
(HttpWebResponse)request.GetResponse();

do any body know how to solve it?

this is the all function

--------------------------------------------------------------------------
-
/// <summary>
/// connect to an internet link, download data, and save it to a file.
/// </summary>
private void DownloadData(string link, string file)
{
HttpWebRequest request;
HttpWebResponse response;
Stream ReceiveStream = null;
FileStream fstr = null;
try
{
request = (HttpWebRequest)WebRequest.Create(link);
request.Credentials = new NetworkCredential(this.txtUserName.Text ,
this.txtUserPass.Text);
response = (HttpWebResponse)request.GetResponse();
ReceiveStream = response.GetResponseStream();
// Now read s into a byte buffer.
byte[] bytes = new byte[100000];
int numBytesToRead = (int)bytes.Length;
int numBytesRead = 0;
while (numBytesToRead > 0)
{
// Read may return anything from 0 to numBytesToRead.
int n = ReceiveStream.Read(bytes, numBytesRead, numBytesToRead);
// The end of the file is reached.
if (n==0)
break;
numBytesRead += n;
numBytesToRead -= n;
}
ReceiveStream.Close();
// numBytesToRead should be 0 now

fstr = new FileStream(file, FileMode.OpenOrCreate,FileAccess.Write);
fstr.Write(bytes, 0, numBytesRead);
fstr.Close();
}
catch(WebException we)
{
throw we;
}
catch(Exception ex)
{
throw ex;
}
finally
{
request = null;
response = null;
}
}
 
O

Ofer B.

Hi Alex
I tried your sample. first with out the SP2.
I close the 2003 Emulator with out saving its state.
than, I ran your sample, it works fine.

after that, I copy the "netcf.all.wce4.X86.cab" file (NET Compact Framework
1.0 SP2 Developer Redistributable) to the 2003 Emulator and answer "Yes" to
replace all.

Than, I ran your sample and got "WebExeption" to the "get" and to the
"Post".

I attached my sample to the "file download". It is running Ok before the SP2
and With WebExeption after SP2.

the 2003 Emulator, my IPAQ 3660, and my QTEK have all, the same behavior.
one more thing, after the installetion of the SP2 on my IPAQ, Icould not use
the internet explorer on the ipaq. and could not connect to my PC. some
thing happened with the connections ???
Ofer


Alex Feinman said:
Chris,

I've just retested on iPaq with SP2 my sample
(http://www.alexfeinman.com/download.asp?doc=FileDownload.zip)
It seems to work fine. Could you try it on your device and in case you are
doing it differently, could you let me know what else should I try?

Alex

Chris Theorin said:
This is happening to me too. A ToString() on the exception object yields
only:

"System.Net.WebException:WebException"

A .Status.ToString() on the WebException object yields:

"ConnectFailure"



Simply uninstall SP2 (use "bare" (no SP) .NET CF in ROM) and run and works
fine...



Alex Feinman said:
Could you provide the complete contents of the WebException (call
.ToString() on it)?


Hi all
I had some code that works fine till the SP2.
I try to download a file from the internet.
after the sp2 I get "WebExeption" for this line: response =
(HttpWebResponse)request.GetResponse();

do any body know how to solve it?

this is the all function

--------------------------------------------------------------------------
-
/// <summary>
/// connect to an internet link, download data, and save it to a file.
/// </summary>
private void DownloadData(string link, string file)
{
HttpWebRequest request;
HttpWebResponse response;
Stream ReceiveStream = null;
FileStream fstr = null;
try
{
request = (HttpWebRequest)WebRequest.Create(link);
request.Credentials = new NetworkCredential(this.txtUserName.Text ,
this.txtUserPass.Text);
response = (HttpWebResponse)request.GetResponse();
ReceiveStream = response.GetResponseStream();
// Now read s into a byte buffer.
byte[] bytes = new byte[100000];
int numBytesToRead = (int)bytes.Length;
int numBytesRead = 0;
while (numBytesToRead > 0)
{
// Read may return anything from 0 to numBytesToRead.
int n = ReceiveStream.Read(bytes, numBytesRead, numBytesToRead);
// The end of the file is reached.
if (n==0)
break;
numBytesRead += n;
numBytesToRead -= n;
}
ReceiveStream.Close();
// numBytesToRead should be 0 now

fstr = new FileStream(file, FileMode.OpenOrCreate,FileAccess.Write);
fstr.Write(bytes, 0, numBytesRead);
fstr.Close();
}
catch(WebException we)
{
throw we;
}
catch(Exception ex)
{
throw ex;
}
finally
{
request = null;
response = null;
}
}
 
O

Ofer B.

Hi Alex

I tried your sample. first with out the SP2.
I close the 2003 Emulator with out saving its state.
than, I ran your sample, it works fine.

after that, I copy the "netcf.all.wce4.X86.cab" file (NET Compact Framework
1.0 SP2 Developer Redistributable) to the 2003 Emulator and answer "Yes" to
replace all.

Than, I ran your sample and got "WebExeption" to the "get" and to the
"Post".


the 2003 Emulator, my IPAQ 3660, and my QTEK have all, the same behavior.
one more thing, after the installetion of the SP2 on my IPAQ, I could not
use
the internet explorer on the ipaq. and could not connect to my PC. some
thing happened with the connections ???
Ofer

Alex Feinman said:
Chris,

I've just retested on iPaq with SP2 my sample
(http://www.alexfeinman.com/download.asp?doc=FileDownload.zip)
It seems to work fine. Could you try it on your device and in case you are
doing it differently, could you let me know what else should I try?

Alex

Chris Theorin said:
This is happening to me too. A ToString() on the exception object yields
only:

"System.Net.WebException:WebException"

A .Status.ToString() on the WebException object yields:

"ConnectFailure"



Simply uninstall SP2 (use "bare" (no SP) .NET CF in ROM) and run and works
fine...



Alex Feinman said:
Could you provide the complete contents of the WebException (call
.ToString() on it)?


Hi all
I had some code that works fine till the SP2.
I try to download a file from the internet.
after the sp2 I get "WebExeption" for this line: response =
(HttpWebResponse)request.GetResponse();

do any body know how to solve it?

this is the all function

--------------------------------------------------------------------------
-
/// <summary>
/// connect to an internet link, download data, and save it to a file.
/// </summary>
private void DownloadData(string link, string file)
{
HttpWebRequest request;
HttpWebResponse response;
Stream ReceiveStream = null;
FileStream fstr = null;
try
{
request = (HttpWebRequest)WebRequest.Create(link);
request.Credentials = new NetworkCredential(this.txtUserName.Text ,
this.txtUserPass.Text);
response = (HttpWebResponse)request.GetResponse();
ReceiveStream = response.GetResponseStream();
// Now read s into a byte buffer.
byte[] bytes = new byte[100000];
int numBytesToRead = (int)bytes.Length;
int numBytesRead = 0;
while (numBytesToRead > 0)
{
// Read may return anything from 0 to numBytesToRead.
int n = ReceiveStream.Read(bytes, numBytesRead, numBytesToRead);
// The end of the file is reached.
if (n==0)
break;
numBytesRead += n;
numBytesToRead -= n;
}
ReceiveStream.Close();
// numBytesToRead should be 0 now

fstr = new FileStream(file, FileMode.OpenOrCreate,FileAccess.Write);
fstr.Write(bytes, 0, numBytesRead);
fstr.Close();
}
catch(WebException we)
{
throw we;
}
catch(Exception ex)
{
throw ex;
}
finally
{
request = null;
response = null;
}
}
 
C

Chris Theorin

The problem is that I wasn't using a fully qualified domain name as my
server URL (compName instead of compName.workname.com).

This is Windows Mobile 2003 device, so if I go Start -> Settings ->
Connections tab -> Connections -> Advanced tab -> Select Networks, and tell
it that 'Programs that automatically connect to a private network should
connect using:' My ISP instead of My Work Network, then the NON-fully
qualified name works just fine (seems kind of backwards to me... seems
something called My Work Network would have a better chance of knowing my
computer name (un-qualified) than anything else).

Same thing happens with SP2 on a PPC 2002 device as well...

This sucks because the default connection settings just don't work properly
anymore for my customers who might not have entered a fully-qualified server
name.

Why wasn't this a requirement in <i>SP0</i> and SP1?

Thanks for all the (misguided) help Alex!

Chris Theorin

Alex Feinman said:
Still works. I've updated the sample at
http://www.alexfeinman.com/download.asp?doc=FileDownload.zip so that now you
can choose the request method. Let me know.

Alex

Chris Theorin said:
Alex... can you do a sample with a "POST" instead of a "GET" and see if it
still works for you? As far as I can tell the "GET" is working just fine.



--------------------------------------------------------------------------
NetworkCredential(this.txtUserName.Text
,
this.txtUserPass.Text);
response = (HttpWebResponse)request.GetResponse();
ReceiveStream = response.GetResponseStream();
// Now read s into a byte buffer.
byte[] bytes = new byte[100000];
int numBytesToRead = (int)bytes.Length;
int numBytesRead = 0;
while (numBytesToRead > 0)
{
// Read may return anything from 0 to numBytesToRead.
int n = ReceiveStream.Read(bytes, numBytesRead, numBytesToRead);
// The end of the file is reached.
if (n==0)
break;
numBytesRead += n;
numBytesToRead -= n;
}
ReceiveStream.Close();
// numBytesToRead should be 0 now

fstr = new FileStream(file, FileMode.OpenOrCreate,FileAccess.Write);
fstr.Write(bytes, 0, numBytesRead);
fstr.Close();
}
catch(WebException we)
{
throw we;
}
catch(Exception ex)
{
throw ex;
}
finally
{
request = null;
response = null;
}
}
 

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