ASP.NET HttpWebRequest POST返回"远程服务器返回错误:(405)方法不允许".仅限VS dev Server

Red*_*Taz 4 asp.net http

我正在使用HttpWebRequest将数据发布到ASP.NET网页(当前在ASP.NET开发服务器上运行)这是代码;

string url = "http://localhost:3333/MySite/";
WebResponse response = null;
try {
    HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);

    ASCIIEncoding encoding = new ASCIIEncoding();
    string postData = "data=test";
    byte[] dataBtyes = encoding.GetBytes(postData);

    request.UserAgent = "Custom Agent";
    request.Method = "POST";
    request.KeepAlive = true;
    request.ContentType = "application/x-www-form-urlencoded";
    request.ContentLength = dataBtyes.Length;

    Stream stream = request.GetRequestStream();
    stream.Write(dataBtyes, 0, dataBtyes.Length);
    stream.Close();

    response = request.GetResponse();
} catch (Exception e) {

}
Run Code Online (Sandbox Code Playgroud)

使用HTTPModule我正在拦截来自"自定义代理"的请求并发送回自定义标头.这适用于GET请求,但是我想要发送的数据可能会超出GET请求允许的限制,所以我想使用POST(如上所述).

我已在真正的IIS服务器上测试了此代码并且它可以工作,但是每次在发送POST数据后调用GetResponse()时,Visual Studio开发服务器都会导致异常"405 Method Not Allowed"(GET工作正常.)

任何人都可以解释为什么开发服务器似乎拒绝POST请求?

编辑:更新问题标题和正文以强调与VS dev服务器一起存在的问题.

Red*_*Taz 6

我发现POST到文件夹地址时会返回"405 Method Not Allowed"错误.(使用上面的问题代码)

VS开发服务器貌似不允许;

......但很高兴;

IIS服务器产生用于误差;

......但很高兴;