WebResponse Problems

  • Thread starter Thread starter Rasika
  • Start date Start date
R

Rasika

Hello

I am trying to connect to our web server to send a http
post. However I get the Exception below thrown.

------
An unhandled exception of type 'System.Net.WebException'
occurred in System.dll

Additional information: The remote server returned an
error: (404) Not Found.
------

I have checked the url and it opens fine. I cant figure
out what I am doing wrong. Please help!

Rasika

=============
String xml = GetXml();

WebRequest request;
WebResponse response;
StreamReader streamReader;
Stream stream;
Byte[] buffer;

request = WebRequest.Create
("http://server.com/xml/uploads/Default.aspx");

//*** Do i need a question mark here
buffer = Encoding.UTF8.GetBytes("?xml=" + xml);
request.Method = "post";

//*** Is this the correct mime type?
request.ContentType = "text/html";
request.ContentLength = buffer.Length;

stream = request.GetRequestStream();
stream.Write(buffer, 0, buffer.Length);
stream.Close();

response = request.GetResponse();

//*** This is where the Exception is thrown
streamReader = new StreamReader(response.GetResponseStream
());
String responseHtml = streamReader.ReadToEnd();

streamReader.Close();
response.Close();

MessageBox.Show(responseHtml);
=============
 
When I try your Url in my web browser, I get back a 404 from the server.
It sounds like you're using the wrong Url in your application.

Mike Boilen
Developer
NET Compact Framework

This posting is provided "AS IS" with no warranties, and confers no rights.
http://www.gotdotnet.com/team/netcf/FAQ.aspx

--------------------
| Content-Class: urn:content-classes:message
| From: "Rasika" <[email protected]>
| Sender: "Rasika" <[email protected]>
| Subject: WebResponse Problems
| Date: Sun, 3 Aug 2003 17:12:44 -0700
| Lines: 55
| Message-ID: <[email protected]>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="iso-8859-1"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
| Thread-Index: AcNaHSDNP3j4LZ0jTamvUFH5pcJfGQ==
| Newsgroups: microsoft.public.dotnet.framework.compactframework
| Path: cpmsftngxa06.phx.gbl
| Xref: cpmsftngxa06.phx.gbl
microsoft.public.dotnet.framework.compactframework:30073
| NNTP-Posting-Host: TK2MSFTNGXA09 10.40.1.161
| X-Tomcat-NG: microsoft.public.dotnet.framework.compactframework
|
|
| Hello
|
| I am trying to connect to our web server to send a http
| post. However I get the Exception below thrown.
|
| ------
| An unhandled exception of type 'System.Net.WebException'
| occurred in System.dll
|
| Additional information: The remote server returned an
| error: (404) Not Found.
| ------
|
| I have checked the url and it opens fine. I cant figure
| out what I am doing wrong. Please help!
|
| Rasika
|
| =============
| String xml = GetXml();
|
| WebRequest request;
| WebResponse response;
| StreamReader streamReader;
| Stream stream;
| Byte[] buffer;
|
| request = WebRequest.Create
| ("http://server.com/xml/uploads/Default.aspx");
|
| //*** Do i need a question mark here
| buffer = Encoding.UTF8.GetBytes("?xml=" + xml);
| request.Method = "post";
|
| //*** Is this the correct mime type?
| request.ContentType = "text/html";
| request.ContentLength = buffer.Length;
|
| stream = request.GetRequestStream();
| stream.Write(buffer, 0, buffer.Length);
| stream.Close();
|
| response = request.GetResponse();
|
| //*** This is where the Exception is thrown
| streamReader = new StreamReader(response.GetResponseStream
| ());
| String responseHtml = streamReader.ReadToEnd();
|
| streamReader.Close();
| response.Close();
|
| MessageBox.Show(responseHtml);
| =============
|
 
Back
Top