我正在使用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服务器一起存在的问题.
我发现POST到文件夹地址时会返回"405 Method Not Allowed"错误.(使用上面的问题代码)
该VS开发服务器貌似不允许;
......但很高兴;
的IIS服务器产生用于误差;
......但很高兴;
| 归档时间: |
|
| 查看次数: |
9608 次 |
| 最近记录: |