2

非常に長いスクリプトを生成し、csv を作成するための汎用ハンドラーにサーバーにポストする JavaScript コードがいくつかあります。

データを送信するための私の 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]);") に追加されていることがわかるため、クライアント側は正常に動作しているようです。

リクエスト/レスポンスを調べるネットワーク ビューでは、「コンテンツ」(フォーム データ属性の名前) が完全ではなく、途中で切れていることがわかります。

サーバー側は非常に単純です - コンテンツを 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;
    }
}

}

私の推測では、より大きな投稿を許可するには、サーバーを何らかの方法で構成する必要があります...

4

1 に答える 1