G
Guest
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(IAsyncResult 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.
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(IAsyncResult 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.