我有一些 JavaScript 代码可以生成很长的脚本,然后将其发回服务器以创建一个 csv 的通用处理程序。
我发送数据的 JavaScript 代码是:
function postwith(to, p) {
var myForm = document.createElement("form");
myForm.method = "post";
myForm.action = to;
for (var k in p) {
var myInput = document.createElement("input");
myInput.setAttribute("name", k);
myInput.setAttribute("value", p[k]);
console.log(k+":"+p[k]);
myForm.appendChild(myInput);
}
document.body.appendChild(myForm);
myForm.submit();
document.body.removeChild(myForm);
在我的控制台中,我可以看到整个字符串都添加到表单中 ("console.log(k+':'+p[k]);"所以客户端似乎工作正常。
在我检查请求/响应的 WebView 中,我可以看到“内容”(表单数据属性的名称)不完整 - 它在中间被切断。
服务器端非常简单 - 以 csv 形式发回内容:
public class Excel : IHttpHandler {
public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "text/csv";
context.Response.AddHeader("Content-Disposition", "attachment; filename=" + context.Request["Report"] +System.DateTime.Now.Ticks+ ".csv");
string content = context.Request["Content"];
content = content.Replace(";", System.Environment.NewLine);
System.Text.UTF8Encoding uc = new System.Text.UTF8Encoding(true);
context.Response.Output.WriteLine(content);
context.Response.End();
}
public bool IsReusable {
get {
return false;
}
}
我的猜测是服务器需要以某种方式配置以允许更大的帖子...
最佳答案
您可以在 web.config 中设置允许的最大内容长度。默认值为 30,000,000 字节:
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="[maxLengthInBytes]" />
</requestFiltering>
</security>
...
</system.webServer>
关于c# - 通用处理程序参数大小限制?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15920985/