473,513 Members | 3,949 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

HttpWebRequest GetResponse 500 Error

Hi,
I've run into a set of errors I don't understand coming back from
HttpWebRequest.GetResponse, In one case, null is returned from the request
without an Exception and in the other the request does not appear to leave my
system yet still returns the 500 error.

In the code below, there is a xml-snippet that I use as a test. When I
run the test using the snippet, the server on the other side logs and
processes the request correctly without error.

But, if the value in the element <DESCRIPTIONSHORTis changed so that
instead of 100 Cotton, it reads 100% Cotton, I get an error back from
GetResponse in the HttpWebResponse object that states the remote server
returned a 500 error. If I change the 100% to 100%%, GetResponse retuns a
null without an exception.

In working with another developer on the remote site, he sees and logs the
first request without error. But in both of the latter cases, the request
never reaches their server.

I'd appreciate any ideas as to what is happening. My searches on the net
have not located anything like this.

Thanks,

Jim
Here is the code:

string itemUpdXml = "&ID=" +
"<STOCKUPDATE>" +
" <SKU>" +
" <NAME>Test</NAME>" +
" <SKU>4359394342</SKU>" +
" <PRICE>24.9900</PRICE>" +
" <DESCRIPTIONSHORT>Men's Polo 100
cotton</DESCRIPTIONSHORT>" +
" <TAXABLE>Y</TAXABLE>" +
" </SKU>" +
"</STOCKUPDATE>";

HttpWebRequest webReq = null;
HttpWebResponse webResp = null;

try
{
webReq =
(HttpWebRequest)WebRequest.Create("http://host.somedomain.com/item.cfm");
webReq.AllowAutoRedirect = true;
webReq.AuthenticationLevel = System.Net.Security.AuthenticationLevel.None;
webReq.KeepAlive = true;
webReq.Method = "POST";
webReq.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0;
..NET CLR 1.1.4322)";
webReq.ContentType = "application/x-www-form-urlencoded";
webReq.ContentLength = itemUpdXml.Length;
webReq.AuthenticationLevel = System.Net.Security.AuthenticationLevel.None;
webReq.KeepAlive = true;

// Write the request
StreamWriter stOut = new StreamWriter(webReq.GetRequestStream(),
System.Text.Encoding.ASCII);
stOut.Write(itemUpdXml);
stOut.Close();

webResp = (HttpWebResponse)webReq.GetResponse();
}
catch (Exception ex)
{
// Do some error processing
}
Aug 17 '08 #1
4 5183
All,

As a follow up to this - through the use of a packet sniffer, I was able to
determine that the request WAS going out to the remote server. The server
was, in fact, generating a 500 error, but long before the application code on
that side was able to execute. So the problem was not on our end, but the
remote end.

That leads to the question of what would cause the remote server to barf on
a single or double percent sign?? It's Cold Fusion on Win 2003.

Thanks, Jim

"Jim Owen" wrote:
Hi,
I've run into a set of errors I don't understand coming back from
HttpWebRequest.GetResponse, In one case, null is returned from the request
without an Exception and in the other the request does not appear to leave my
system yet still returns the 500 error.

In the code below, there is a xml-snippet that I use as a test. When I
run the test using the snippet, the server on the other side logs and
processes the request correctly without error.

But, if the value in the element <DESCRIPTIONSHORTis changed so that
instead of 100 Cotton, it reads 100% Cotton, I get an error back from
GetResponse in the HttpWebResponse object that states the remote server
returned a 500 error. If I change the 100% to 100%%, GetResponse retuns a
null without an exception.

In working with another developer on the remote site, he sees and logs the
first request without error. But in both of the latter cases, the request
never reaches their server.

I'd appreciate any ideas as to what is happening. My searches on the net
have not located anything like this.

Thanks,

Jim
Here is the code:

string itemUpdXml = "&ID=" +
"<STOCKUPDATE>" +
" <SKU>" +
" <NAME>Test</NAME>" +
" <SKU>4359394342</SKU>" +
" <PRICE>24.9900</PRICE>" +
" <DESCRIPTIONSHORT>Men's Polo 100
cotton</DESCRIPTIONSHORT>" +
" <TAXABLE>Y</TAXABLE>" +
" </SKU>" +
"</STOCKUPDATE>";

HttpWebRequest webReq = null;
HttpWebResponse webResp = null;

try
{
webReq =
(HttpWebRequest)WebRequest.Create("http://host.somedomain.com/item.cfm");
webReq.AllowAutoRedirect = true;
webReq.AuthenticationLevel = System.Net.Security.AuthenticationLevel.None;
webReq.KeepAlive = true;
webReq.Method = "POST";
webReq.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0;
.NET CLR 1.1.4322)";
webReq.ContentType = "application/x-www-form-urlencoded";
webReq.ContentLength = itemUpdXml.Length;
webReq.AuthenticationLevel = System.Net.Security.AuthenticationLevel.None;
webReq.KeepAlive = true;

// Write the request
StreamWriter stOut = new StreamWriter(webReq.GetRequestStream(),
System.Text.Encoding.ASCII);
stOut.Write(itemUpdXml);
stOut.Close();

webResp = (HttpWebResponse)webReq.GetResponse();
}
catch (Exception ex)
{
// Do some error processing
}

Aug 18 '08 #2

"Jim Owen" <ji**@online.nospamwrote in message
news:70**********************************@microsof t.com...
All,

As a follow up to this - through the use of a packet sniffer, I was able
to
determine that the request WAS going out to the remote server. The server
was, in fact, generating a 500 error, but long before the application code
on
that side was able to execute. So the problem was not on our end, but the
remote end.

That leads to the question of what would cause the remote server to barf
on
a single or double percent sign?? It's Cold Fusion on Win 2003.

Thanks, Jim
The Web server should have dumped the error in its log with more information
as to the cause of the error.

Aug 18 '08 #3
"Jim Owen" <ji**@online.nospamwrote in message
news:0C**********************************@microsof t.com...
>...
Here is the code:

string itemUpdXml = "&ID=" +
"<STOCKUPDATE>" +
" <SKU>" +
" <NAME>Test</NAME>" +
" <SKU>4359394342</SKU>" +
" <PRICE>24.9900</PRICE>" +
" <DESCRIPTIONSHORT>Men's Polo 100
cotton</DESCRIPTIONSHORT>" +
" <TAXABLE>Y</TAXABLE>" +
" </SKU>" +
"</STOCKUPDATE>";
I strongly suggest that you never do this again. XML is not text and must
not be constructed using string concatenation. What are you planning to do
it the description field contains characters that are illegal in XML? Use an
XmlWriter instead, or else construct your XML in an XmlDocument and then
send the contents of that. Both of these mechanisms understand XML, and will
properly encode characters that are not permitted.

Your current issue is probably due to the fact that you didn't URL Encode
your XML. Percent-sign is treated specially in a URL. Have you ever seen a
URL containing, for instance, %20?

--
John Saunders | MVP - Connected System Developer

Aug 18 '08 #4
Hi John,

The sample XML that is within the code is there simply and only as a
debugging test case - I needed something I could use to duplicate the problem
reliably.

That said, we're still running into the problem - there's been no luck on
the remote side. However, they suggested as well that I URL encode the xml
for testing, which I've tried but again without success.

Here's the updated test code:
HttpWebRequest webReq = null;

webReq = (HttpWebRequest)WebRequest.Create(URLStr);
webReq.Method = "POST";

ASCIIEncoding encoding = new ASCIIEncoding();

string dataStr = HttpUtility.UrlEncode(xmlStr);

webReq.ContentType = "application/x-www-form-urlencoded";

// Send the data.
byte[] data = Encoding.ASCII.GetBytes(dataStr);
webReq.ContentLength = data.Length;

Stream newStream = webReq.GetRequestStream();
newStream.Write(data, 0, data.Length);
newStream.Close();

webResp = (HttpWebResponse)webReq.GetResponse();
Still receiving the 500 error from the remote Cold Fusion server.

Any help would be appreciated.

- Jim
"John Saunders" wrote:
"Jim Owen" <ji**@online.nospamwrote in message
news:0C**********************************@microsof t.com...
...
Here is the code:

string itemUpdXml = "&ID=" +
"<STOCKUPDATE>" +
" <SKU>" +
" <NAME>Test</NAME>" +
" <SKU>4359394342</SKU>" +
" <PRICE>24.9900</PRICE>" +
" <DESCRIPTIONSHORT>Men's Polo 100
cotton</DESCRIPTIONSHORT>" +
" <TAXABLE>Y</TAXABLE>" +
" </SKU>" +
"</STOCKUPDATE>";

I strongly suggest that you never do this again. XML is not text and must
not be constructed using string concatenation. What are you planning to do
it the description field contains characters that are illegal in XML? Use an
XmlWriter instead, or else construct your XML in an XmlDocument and then
send the contents of that. Both of these mechanisms understand XML, and will
properly encode characters that are not permitted.

Your current issue is probably due to the fact that you didn't URL Encode
your XML. Percent-sign is treated specially in a URL. Have you ever seen a
URL containing, for instance, %20?

--
John Saunders | MVP - Connected System Developer

Aug 19 '08 #5

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

Similar topics

10
19308
by: Gregory A Greenman | last post by:
I'm trying to write a program in vb.net to automate filling out a series of forms on a website. There are three forms I need to fill out in sequence. The first one is urlencoded. My program is able to fill that one out just fine. The second form is multipart/form-data. Unfortunately, I haven't been able to fill that out in a way that makes...
1
12575
by: Jeff B | last post by:
I'm trying to create a simple screen scraping application and I kept getting a System.Net.WebException thrown back with a message of "The operation has timed-out." At first I thought it was some kind of connectivity issue on the machine. It didn't make sense though, because I can open up a browser on the same machine and easily browse the...
17
665
by: warlord | last post by:
I have a windows client app that is trying to download a file from a web server but I always get the following error when I call the GetResponse method of the Request object. The remote server returned an error: (404) Not Found. When I run it against a website on my local machine everything works perfectly, but not against the remote...
2
14073
by: Steve Richter | last post by:
I have a page that uses simple HTTP GET to do an ISBN lookup via Amazon.com. The page works when I run it from //localhost. But I have moved it to my godaddy.com shared hoster site, and I get errors on the HttpWebRequest.GetResponse statement. The remote server returned an error: (401) Unauthorized also, when I use the network...
2
20166
by: GlennLanier | last post by:
Hello, I've searched the forums and can't find an answer -- if it i there, kindly point me in that direction. I would like to simulate a browser POSTing a FORM and be able to pars the response. I have the following code in my Page_Load (litResponse is defined a <ASP:Literal>):
2
8716
by: Maris Janis Vasilevskis | last post by:
Hi, Is it possible to force HttpWebRequest to do exactly (not approximately) the same as MSXML2.ServerXMLHTTP does? More details. I port JScript to JScript.NET I have a server (ASP invoking binary code; code not accessible). I send XML requests to it. If my request is accepted, ServerXMLHTTP returns XML with accept details. If my...
1
1427
by: mroffey | last post by:
Hi I'm using the code below to post to a web form, but when I run it, i get System.Net.WebException: The operation has timed-out. error Obviously something is wrong, can anyone give me a clue? string url = "http://localhost/testapp/test.asp"; HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(url);...
5
4853
by: mr.newsgroupguy | last post by:
I am working in C# .NET 1.1. My app has a button on its main form that checks to see if it has access to a file on our server, just an XML file. On our server we are running W2K IIS with a virtual directory, set to Windows Authentication. I am creating an HTTPWebRequest object on the client, and setting its Credentials to...
7
7653
by: Marc Bartsch | last post by:
Hi, I have a background worker in my C# app that makes a synchronous HttpWebRequest.GetResponse() call. The idea is to POST a file to a server on the internet. When I call HttpWebRequest.Abort() on the request object on another thread, GetResponse() returns with an exception as expected. However, when I monitor the network traffic, it does...
0
7270
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7178
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7397
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7543
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5703
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5102
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
1612
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
813
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
470
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.