我想使用我的 Windows 应用程序将多个图像文件上传到 Web 服务器。这是我的代码
public void UploadMyFile(string URL, string localFilePath)
{
HttpWebRequest req=(HttpWebRequest)WebRequest.Create(URL);
req.Method = "PUT";
req.AllowWriteStreamBuffering = true;
// Retrieve request stream and wrap in StreamWriter
Stream reqStream = req.GetRequestStream();
StreamWriter wrtr = new StreamWriter(reqStream);
// Open the local file
StreamReader rdr = new StreamReader(localFilePath);
// loop through the local file reading each line
// and writing to the request stream buffer
string inLine = rdr.ReadLine();
while (inLine != null)
{
wrtr.WriteLine(inLine);
inLine = rdr.ReadLine();
}
rdr.Close();
wrtr.Close();
req.GetResponse();
}
我参考了以下链接 http://msdn.microsoft.com/en-us/library/aa446517.aspx
我收到异常远程服务器返回了意外响应:(405)方法不允许。