473,499 Members | 1,576 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

HttpWebRequest.GetRequestStream Causes an Exception

I'm having a hard time getting a call to HttpWebRequest's
GetRequestSteam to work. Each time I try to run it, I get the
following error:
The underlying connection was closed: Unable to connect to the
remote server.

Description: An unhandled exception occurred during the execution of
the current web request. Please review the stack trace for more
information about the error and where it originated in the code.

Exception Details: System.Net.WebException: The underlying
connection was closed: Unable to connect to the remote server.

Source Error:

An unhandled exception was generated during the execution of the
current web request. Information regarding the origin and location
of the exception can be identified using the exception stack trace
below.

Stack Trace:
[WebException: The underlying connection was closed: Unable to
connect to the remote server.]
System.Net.HttpWebRequest.CheckFinalStatus() +677
System.Net.HttpWebRequest.EndGetRequestStream(IAsy ncResult
asyncResult) +75
System.Net.HttpWebRequest.GetRequestStream() +233
ERSI.Store.UPSShipping.RequestShipping() +113
...
The code I use works perfectly on both my development machine and on
another webserver where we host our main website. However, when I try
to run this on a our internal company web server (running Microsoft
Small Business Server, ISA Firewall, and IIS 6), it seems to timeout
and give me the error above.

The following code produces the error:
string szResponse = "";
Uri url = new Uri("https://www.ups.com/ups.app/xml/Rate");
HttpWebRequest connection = (HttpWebRequest)WebRequest.Create(url);
connection.UnsafeAuthenticatedConnectionSharing = true;
connection.Method = "POST";
Stream output = connection.GetRequestStream(); // <-- Error Thrown

string szXML = GetRequestString();
ASCIIEncoding encoding = new ASCIIEncoding();
byte[] request = encoding.GetBytes(szXML);
output.Write(request, 0, request.Length);
output.Close();

HttpWebResponse resp = (HttpWebResponse)connection.GetResponse();
StreamReader strStream = new StreamReader(resp.GetResponseStream(),
Encoding.ASCII);

try {
szResponse = strStream.ReadToEnd();
} catch (Exception exc) {
System.Diagnostics.Debug.WriteLine(exc.StackTrace) ;
}

resp.Close();
Because it works great on both our development machines and our main
websites, I don't think that the problem is with the code, but rather
some setting in ISA or SBS. I would appreciate any suggestions on how
to fix the problem or even an alternate newsgroup to try if nobody has
any ideas. Thanks.

--
Jason

Nov 19 '05 #1
3 9862
see if you can ping the url/domain from the webserver or launch a browser on
the server and see if you can hit the url. usually, this type of exception
gets thrown when the server can't connect to the url

--
Regards,
Alvin Bruney
[Shameless Author Plug]
The Microsoft Office Web Components Black Book with .NET
available at www.lulu.com/owc
_________________________
"Jason" <ja***@elkriversystems.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
I'm having a hard time getting a call to HttpWebRequest's
GetRequestSteam to work. Each time I try to run it, I get the
following error:
The underlying connection was closed: Unable to connect to the
remote server.

Description: An unhandled exception occurred during the execution of
the current web request. Please review the stack trace for more
information about the error and where it originated in the code.

Exception Details: System.Net.WebException: The underlying
connection was closed: Unable to connect to the remote server.

Source Error:

An unhandled exception was generated during the execution of the
current web request. Information regarding the origin and location
of the exception can be identified using the exception stack trace
below.

Stack Trace:
[WebException: The underlying connection was closed: Unable to
connect to the remote server.]
System.Net.HttpWebRequest.CheckFinalStatus() +677
System.Net.HttpWebRequest.EndGetRequestStream(IAsy ncResult
asyncResult) +75
System.Net.HttpWebRequest.GetRequestStream() +233
ERSI.Store.UPSShipping.RequestShipping() +113
...
The code I use works perfectly on both my development machine and on
another webserver where we host our main website. However, when I try
to run this on a our internal company web server (running Microsoft
Small Business Server, ISA Firewall, and IIS 6), it seems to timeout
and give me the error above.

The following code produces the error:
string szResponse = "";
Uri url = new Uri("https://www.ups.com/ups.app/xml/Rate");
HttpWebRequest connection = (HttpWebRequest)WebRequest.Create(url);
connection.UnsafeAuthenticatedConnectionSharing = true;
connection.Method = "POST";
Stream output = connection.GetRequestStream(); // <-- Error Thrown

string szXML = GetRequestString();
ASCIIEncoding encoding = new ASCIIEncoding();
byte[] request = encoding.GetBytes(szXML);
output.Write(request, 0, request.Length);
output.Close();

HttpWebResponse resp = (HttpWebResponse)connection.GetResponse();
StreamReader strStream = new StreamReader(resp.GetResponseStream(),
Encoding.ASCII);

try {
szResponse = strStream.ReadToEnd();
} catch (Exception exc) {
System.Diagnostics.Debug.WriteLine(exc.StackTrace) ;
}

resp.Close();
Because it works great on both our development machines and our main
websites, I don't think that the problem is with the code, but rather
some setting in ISA or SBS. I would appreciate any suggestions on how
to fix the problem or even an alternate newsgroup to try if nobody has
any ideas. Thanks.

--
Jason

Nov 19 '05 #2
I get no response on the webserver. It connects and returns some basic
information on my own computer.

--
Jason

Nov 19 '05 #3
I case anyone is interested or is having a similar problem, I managed
to track the problem down. I did a side-by-side comparison of the ISA
settings on the webserver that working and the one that wasn't. After
try a variety of different settings, I noticed two packet filters that
were missing on the problem machine.

Under Access Policy -> IP Packet Filtering, I added the following
filters:

- SSL Access
IP Protocol: TCP
Direction: Outbound
Local Port: All ports
Remote port: Fixed port
Remote port number: 443
Applies to: Default IP Address(es) on the external interface(s)
Applies to: All remote computers

- Web Access
IP Protocol: TCP
Direction: Outbound
Local Port: All ports
Remote port: Fixed port
Remote port number: 80
Applies to: Default IP Address(es) on the external interface(s)
Applies to: All remote computers

Apparently, these filters were created on our other servers by default
(or by a different administrator), but for some reason were not on this
one. Probably something an experienced network administrator would
have picked up on immediately, but hopefully this will help any novice
administrators who happen to run into a similar problem.

--
Jason

Nov 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2317
by: Kari Hallfast | last post by:
Hi, I'm a C++ programmer and I have just recently decided to use Python as an embedded scripting language. I call Py_Initialize(), run a few scripts and call PyFinalize() which causes an unhandled...
8
2485
by: SunshineGirl | last post by:
I'm trying to trigger an app with the following code from a message queue. It works with only the message box voilą! enabled. But it causes the exception below when it is triggered with the rest of...
3
7829
by: Dan | last post by:
I'm experimenting with HttpWebRequest. After I've created a request: m_request = (HttpWebRequest) WebRequest.Create(uri); I'd like to repeatedly send requests to the URI, as follows: public...
1
1618
by: iana_kosio | last post by:
Hi, I am using HttpWebRequest class to communicate with remote server. In some cases the server would return 5xx status code which results in HttpWebRequest object throwing an exception. I,...
0
1419
by: a_newcomb | last post by:
I have an application which polls and connects to a webserver on a background thread. When the application is supposed to exit, I call abort on the HttpWebRequest object. I have observed that...
1
2411
by: SmilingJoe88 | last post by:
Can anyone tell me what I can do to resolve this error? This is a screen scraping example which is running on Windows XP Pro, using IIS-PWS 5.1. The example code I am using can be found at the...
3
3196
by: doubts | last post by:
Hi all, I am trying to convert my bulk of code from VC++ 6.0 to VC++.Net. when using std::string type variable, the application causes exception at one instance and does not cause an exception at...
1
4055
by: Ollie Riches | last post by:
Hi, I am recieving an exception when adding support for MTOM to a web config file that is using WSE3.0 to talk to a web service. when the following section is added: <messaging> <mtom...
2
3193
by: ZadaheaD | last post by:
Hello, i really need your help on this one. im trying to pass an XML by a web service using HttpWebRequest and a POST Method. here is my code : HttpWebRequestObj =...
0
7132
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7178
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6899
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7390
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5475
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4602
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3103
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3094
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
665
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.