我使用Web将Xml作为字符串发送到我创建的另一台服务器。当调用UploadString时,我得到一个(500个内部服务器错误)。我调试的服务无疑是抛出异常,但我从来没有到达那里!(也有一个日志来证明这一点)。我使用web客户端的方式如下:
using(WebClient webclient = new WebClient())
{
webclient.Encoding = UTF8Encoding.UTF8;
webclient.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
webclient.UseDefaultCredentials = true;
webclient.UploadString(url, stringToUpload);
}我知道以下事实:
我发送的字符串的大小有限制吗?如果是的话,我应该做些什么来启用此发送,或者是否有其他方法来处理这种情况?此外,如果服务器实际上不是内部服务器错误,为什么要抛出500?
谢谢
发布于 2014-10-06 12:39:33
是的,当请求发送到asp.net时有一个限制:
<configuration>
<system.web>
<httpRuntime maxRequestLength="1048576" />
</system.web>
</configuration>(在iis7上,它是:
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="1073741824" />
</requestFiltering>
</security>
</system.webServer>)
检查您的远程服务,看看您的请求长度是否不太大。还请注意请求超时,这可能会减少您的上传,如果需要太长时间)有解决方案,以避免这个问题:块您的请求,或使用框架,能够直接处理它。
从服务器的角度来看,它被用作内部错误,但是您也许可以通过将错误传递到something else来更改行为。
发布于 2016-06-13 09:28:32
增加执行超时,但:
<system.web>
<httpRuntime executionTimeout="200" maxRequestLength="1048576" />
</system.web>发布于 2020-03-09 09:40:04
尝试先发送一个空白刺,然后再发送实际字符串。
using(WebClient webclient = new WebClient())
{
webclient.Encoding = UTF8Encoding.UTF8;
webclient.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
webclient.UseDefaultCredentials = true;
blankString="";
webclient.UploadString(url, blankString);
webclient.UploadString(url, stringToUpload);
}https://stackoverflow.com/questions/26216328
复制相似问题