473,403 Members | 2,293 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,403 software developers and data experts.

WebException Method not allowed

Hello,
I am trying to use WebClient class's UploadData method for uploading
data to a particular uri. I ahve created a text file say new.txt in the
IISROOT folder. But when I try to upload data to this file using uri
http://localhost/new.txt it gives following exception

Uploading to http://localhost/new.txt ...
The remote server returned an error: (405) Method Not Allowed. at
System.Net.
HttpWebRequest.CheckFinalStatus()
at System.Net.HttpWebRequest.EndGetResponse(IAsyncRes ult asyncResult)
at System.Net.HttpWebRequest.GetResponse()
at System.Net.WebClient.UploadData(String address, String method, Byte[]
data
)
at HTTPPostConsole.Class1.Main(String[] args) in
f:\httppostconsole\class1.cs
:line 33

My code is

string uriString;
Console.Write("\nPlease enter the URI to post data to {for example,
http://www.contoso.com} : ");
uriString = Console.ReadLine();
// Create a new WebClient instance.
WebClient myWebClient = new WebClient();
Console.WriteLine("\nPlease enter the data to be posted to the URI
{0}:",uriString);
string postData = Console.ReadLine();
myWebClient.Headers.Add("Content-Type","application/x-www-form-urlencoded");

// Apply ASCII Encoding to obtain the string as a byte array.
byte[] byteArray = Encoding.ASCII.GetBytes(postData);
Console.WriteLine("Uploading to {0} ...", uriString);

// Upload the input string using the HTTP 1.0 POST method.
byte[] responseArray = myWebClient.UploadData(uriString,"POST",byteArray) ;

Ths same code works fine if I give uri as www.contoso.com.

How can I solve this problem.
Nov 17 '05 #1
3 12094
Are you sure that your webserver security settings are configured
correctly?

"405 errors often arise with the POST method. You may be trying to
introduce some kind of input form on your Web site, but not all ISPs
allow the POST method necessary to process the form.

All 405 errors can be traced to configuration of the Web server and
security governing access to the content of the Web site, so should
easily be explained by your ISP."

From: http://www.checkupdown.com/status/E405.html

Nov 17 '05 #2
Are you sure that your webserver security settings are configured
correctly?

"405 errors often arise with the POST method. You may be trying to
introduce some kind of input form on your Web site, but not all ISPs
allow the POST method necessary to process the form.

All 405 errors can be traced to configuration of the Web server and
security governing access to the content of the Web site, so should
easily be explained by your ISP."

From: http://www.checkupdown.com/status/E405.html

Nov 17 '05 #3
sushi wrote:
Hello,
I am trying to use WebClient class's UploadData method for
uploading data to a particular uri. I ahve created a text file say
new.txt in the IISROOT folder. But when I try to upload data to this
file using uri http://localhost/new.txt it gives following exception

Uploading to http://localhost/new.txt ...
The remote server returned an error: (405) Method Not Allowed. at
System.Net.
HttpWebRequest.CheckFinalStatus()
at System.Net.HttpWebRequest.EndGetResponse(IAsyncRes ult
asyncResult) at System.Net.HttpWebRequest.GetResponse()
at System.Net.WebClient.UploadData(String address, String method,
Byte[] data
)
at HTTPPostConsole.Class1.Main(String[] args) in
f:\httppostconsole\class1.cs
:line 33

My code is

string uriString;
Console.Write("\nPlease enter the URI to post data to {for example,
http://www.contoso.com} : ");
uriString = Console.ReadLine();
// Create a new WebClient instance.
WebClient myWebClient = new WebClient();
Console.WriteLine("\nPlease enter the data to be posted to the URI
{0}:",uriString);
string postData = Console.ReadLine();
myWebClient.Headers.Add("Content-Type","application/x-www-form-urlenco
ded");

// Apply ASCII Encoding to obtain the string as a byte array.
byte[] byteArray = Encoding.ASCII.GetBytes(postData);
Console.WriteLine("Uploading to {0} ...", uriString);

// Upload the input string using the HTTP 1.0 POST method.
byte[] responseArray =
myWebClient.UploadData(uriString,"POST",byteArray) ;

Ths same code works fine if I give uri as www.contoso.com.

How can I solve this problem.


First, use UploadValues() to post form data. UploadData() is meant to
be sued for "raw" posts like posting binaries (i.e. uploads).

Second, what are you trying to achieve? Are you trying to upload a file
instead? You cannot post values to some arbitrary file -- there must be
some application at the backend processing a POST.

Cheers,
--
http://www.joergjooss.de
mailto:ne********@joergjooss.de
Nov 17 '05 #4

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

Similar topics

0
by: Joe Bloggs | last post by:
I have a C# MRS application that uses the ReportingService's Render method to retrieve a byte array containing a report. The following error message occurs An unhandled exception of type...
2
by: genc_ ymeri at hotmail dot com | last post by:
Hi, I'm trying to recieve the response status code rather than the message in the below code : try { responseArray = myWebClient.UploadValues(uriString,"POST",myNameValueCollection); }...
0
by: sushi | last post by:
Hello, I am trying to use WebClient class's UploadData method for uploading data to a particular uri. I ahve created a text file say new.txt in the IISROOT folder. But when I try to upload data to...
1
by: etantonio | last post by:
Good morning, I've a problem, in the past I translate my site from google or altavista with a code similar to this : <%@ Page Language="c#" Trace="true" Debug="true" %> <%@ import...
1
by: Albert Ludwig | last post by:
Hallo NewsGroup, in meiner Anwendung rufe ich ein Internet-asp-script auf. Diese Funktionalität habe ich in der Funktion "fuwHandelWebRequestPost" (siehe unten) gekapselt. Diese Funktion...
8
by: Tim Reynolds | last post by:
Our .Net application calls a web method of aplpication 2 that resides on their Apache server. When I as a developer C#, Studios 2003, make the call to their web method from my desktop, I receive no...
2
by: Scott McFadden | last post by:
When I invoke two web service methods sequentially with no delay, the first web method invocation goes smooth while the 2nd one generates the dredded: System.Net.WebException: The underlying...
4
by: =?Utf-8?B?UGhpbGlwIEs=?= | last post by:
Simplifying the code a bit its like this: try { myRemotingObj.Myfunction(string, string,string,string,timeSpan) } catch(WebException) { commsUp = false; }
5
by: repairman2003 | last post by:
I am getting the following error when trying to call GetRequestStream(): System.Net.WebException: The requested URI is invalid for this FTP command.. Code where the exception catches: ......
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
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
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
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,...

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.