473,397 Members | 2,068 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Problem HttpWebRequest from asp.net app

I created a class to submit an xml document to a webpage.

When I use my class in a console application, everything submits correctly.

However, when I attempt to use my class from an asp.net webpage, then it
always gives me this exception
The underlying connection was closed: Unable to connect to the remote server.

I am using the System.Net namespace
Code is below:

I always get the exception on this line:
using (Stream requestStream = request.GetRequestStream())

Thanks in advance for any hints. tips to solve this problem

public string SubmitIRAlerts(string url)
{
string returnValue;
StreamReader sr;
ASCIIEncoding enc = new ASCIIEncoding();
byte[] bytes = enc.GetBytes(this.XmlData);
HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
request.Method = "POST";
request.ContentLength = bytes.Length;
request.ContentType = "text/xml";
using (Stream requestStream = request.GetRequestStream())
// always produces error on code above
{
requestStream.Write(bytes, 0, bytes.Length);
}
HttpWebResponse response = (HttpWebResponse) request.GetResponse();
try
{
if (response.StatusCode != HttpStatusCode.OK)
{
string message = String.Format("POST failed. Received HTTP {0}",
response.StatusCode);
throw new ApplicationException(message);
}
sr = new StreamReader(response.GetResponseStream());
try
{
returnValue = sr.ReadToEnd();
}
finally
{
if ( sr != null )
sr.Close();
}
}
finally
{
if ( response != null )
response.Close();
}
return returnValue;
}

Mar 27 '06 #1
6 1745
Thus wrote Darren,
I created a class to submit an xml document to a webpage.

When I use my class in a console application, everything submits
correctly.

However, when I attempt to use my class from an asp.net webpage, then
it
always gives me this exception
The underlying connection was closed: Unable to connect to the remote
server.
I am using the System.Net namespace
Code is below:
I always get the exception on this line:
using (Stream requestStream = request.GetRequestStream())
Thanks in advance for any hints. tips to solve this problem


Just to be sure... you also get the error when running the ASP.NET page on
your local machine, on which the console application works?

Cheers,
--
Joerg Jooss
ne********@joergjooss.de
Mar 27 '06 #2
I only get the error when I run the class from an ASP.NET page. It works fine
if i call the class from a console application

It is not an asp.net web service that I am calling, it is an classic asp
page. It is a 3rd party site, so I have no control over it.

"Joerg Jooss" wrote:

Just to be sure... you also get the error when running the ASP.NET page on
your local machine, on which the console application works?

Cheers,
--
Joerg Jooss
ne********@joergjooss.de

Mar 28 '06 #3
Thus wrote Darren,
I only get the error when I run the class from an ASP.NET page. It
works fine if i call the class from a console application


Hm... that seems totally bizarre to me.

Well, just to be sure, you could switch your implementation to WebClient.UploadData()
and see if that makes a difference.

Cheers,
--
Joerg Jooss
ne********@joergjooss.de
Mar 28 '06 #4
I'll create a test app and get back with my results

"Joerg Jooss" wrote:
Thus wrote Darren,
I only get the error when I run the class from an ASP.NET page. It
works fine if i call the class from a console application


Hm... that seems totally bizarre to me.

Well, just to be sure, you could switch your implementation to WebClient.UploadData()
and see if that makes a difference.

Cheers,
--
Joerg Jooss
ne********@joergjooss.de

Mar 29 '06 #5
Joerg

I found the problem with my code.
I needed to create a WebProxy object and add it to the HttpWebRequest object.

Darren

Mar 31 '06 #6
Thus wrote Darren,
Joerg

I found the problem with my code.
I needed to create a WebProxy object and add it to the HttpWebRequest
object.


Ah... yes, of course. The console app runs under your identity and thus can
obtain your system's default proxy. The ASP.NET user quite likely doesn't
have a proxy configuration.

Cheers,
--
Joerg Jooss
ne********@joergjooss.de
Mar 31 '06 #7

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

Similar topics

0
by: TJO | last post by:
Can someone at MS please reply to this. I am trying to post data so a web form via ssl with the following code. I keep getting this error: "The underlying connection was closed: Could not...
1
by: Satinderpal Singh | last post by:
Hi everyone, We are using HttpWebRequest to create a request to a URI, which requires us to login first. In order to process all the transactions, first we have to login and get the cookie value...
4
by: R Reyes | last post by:
I am trying to code a file uploader (for forum/email attachments) from the client computer to a remote web server via the PUT method (since POST is not allowed ). However, the upload works ONLY...
22
by: Kristof Thys | last post by:
Hello, I'm developing a C# - windows forms application. To get some information for my application, I'm connecting to an URL, wich gives me XML generated using php. With 90% of the users, this...
1
by: Satinderpal Singh | last post by:
Hi everyone, We are using HttpWebRequest to create a request to a URI, which requires us to login first. In order to process all the transactions, first we have to login and get the cookie value...
5
by: japslam japslam via DotNetMonster.com | last post by:
Hi all, I have problem when I use HttpWebRequest and take long time to call to my service server. If at that time there are many request comes in semultaneous, I will get this exception ...
5
by: bg | last post by:
Hi all. I 'm trying to automate some of my workflow, by doing some programmatic "POST"s to an internal webserver via HttpWebRequest. The Code is your usual straight forward type of thing. ...
6
by: Georg | last post by:
Hello, I am trying to load a web page over a HTTP proxy with the POST method and I am using the following code: // open request (string url) HttpWebRequest httpWebRequest =...
0
by: davidpenty | last post by:
Hi there, I am having some problems with a multi-threaded asp.net seach page. My search page sends off four asynchronous http requests to four search engines then waits for the results to come...
1
by: Proogeren | last post by:
I have a problem with a httpwebrequest that I am creating. The request in itself looks correct but using fiddler I see that a www-authentication header is sent along as well. The code is pasted...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.