The remote server returned an error: (405) Method Not Allowed
I am trying to implement a REST WCF service to post a file from a WPF application to my server, however I am getting the 405 error. Before contacting my ISP, can anyone tell me if my code looks ok? I know that most probably its something to do with the server not accepting the Post method, but just wanted to make sure that my code is ok. Here it is :-
public static void UploadFile()
{
string serverPath = "http://www.mywebsites.com/test/";
string filePath = "C:\\Testing\\asd_asd_Feedback.xml";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(serverPath);
request.Accept = "text/xml";
request.Method = "PUT";
request.Credentials = new System.Net.NetworkCredential("testjo", "");
using (FileStream fileStream = File.OpenRead(filePath))
using (Stream requestSt开发者_如何学Goream = request.GetRequestStream())
{
int bufferSize = 1024;
byte[] buffer = new byte[bufferSize];
int byteCount = 0;
while ((byteCount = fileStream.Read(buffer, 0, bufferSize)) > 0)
{
requestStream.Write(buffer, 0, byteCount);
}
}
string result = String.Empty;
try
{
using (WebResponse response = request.GetResponse())
using (StreamReader reader = new StreamReader(response.GetResponseStream()))
{
result = reader.ReadToEnd();
}
}
catch (Exception exc)
{
}
Console.WriteLine(result);
}
Basically its failing on the request.GetResponse()
Thanks for your help!
精彩评论