473,473 Members | 1,755 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 12097
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: 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
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,...
1
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...
0
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
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...
0
muto222
php
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.