远程服务器返回错误:(405)不允许的方法 [英] The remote server returned an error: (405) Method Not Allowed

查看:296
本文介绍了远程服务器返回错误:(405)不允许的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用HttpWebRequest将文件发布到服务器:

I want to use HttpWebRequest to post a file to the server:

private void testUpload()
{
    FileStream source = File.Open(@"C:\test.txt", FileMode.Open);

    var request = 
    (HttpWebRequest)WebRequest.Create(new Uri("http://example.com/Project/"));
    request.Method = "POST";

   request.BeginGetResponse(DataUploadCompleted, request);
}

private void DataUploadCompleted(IAsyncResult ar)
{
    var request = (HttpWebRequest)ar.AsyncState;
    var response = request.EndGetResponse(ar);
}

我遇到了这个异常:

远程服务器返回错误:(405)不允许使用方法.

The remote server returned an error: (405) Method Not Allowed.

当我访问:" http://example.com/Project/"时,页面显示:

When I access: "http://example.com/Project/", the page shows:

Directory Listing Denied

This Virtual Directory does not allow contents to be listed.


但是,我已经为文件夹:project设置了chmod 777,并允许IIS用户在上面上传文件(具有完全权限).


However, I already chmod 777 for the folder: project and allow IIS user to upload files on it (full permission).

为什么我会遇到例外情况?

Why I got that exception?

我正在寻找解决方案.有人建议使用:

I searched for a solution. Some people advices to use:

NetworkCredential myCred = new NetworkCredential("myusername", "mypassword");
request.Credentials = myCred;

myusername和mypassword是FTP的帐户吗?

Is myusername and mypassword the account of the FTP?

如果我必须使用FTP帐户,那么我不喜欢这样.我可以使用其他一些凭证而不是FTP帐户吗?因为我不想提供ftp帐户,所以人们可以在我的服务器上进行访问.

If I have to use FTP account, then I don't like that. Can I use some other credentials rather then FTP account? Because I don't want to give the ftp account and people will access on my server.

推荐答案

我需要在服务器上添加一个网页来处理上传.

I need to add a webpage on the server to handle the uploading.

这篇关于远程服务器返回错误:(405)不允许的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆