1

私の方法は次のようになります。

public string Request(string action, NameValueCollection parameters, uint? timeoutInSeconds = null)
{
    parameters = parameters ?? new NameValueCollection();
    ProvideCredentialsFor(ref parameters);

    var data = parameters.ToUrlParams(); // my extension method converts the collection to a string, works well

    byte[] dataStream = Encoding.UTF8.GetBytes(data);
    string request = ServiceUrl + action;
    var webRequest = (HttpWebRequest)WebRequest.Create(request);
    webRequest.AllowAutoRedirect = false;
    webRequest.Method = "POST";
    webRequest.ContentType = "application/x-www-form-urlencoded";
    webRequest.ContentLength = dataStream.Length;
    webRequest.Timeout = (int)(timeoutInSeconds == null ? DefaultTimeoutMs : timeoutInSeconds * 1000);
    webRequest.Proxy = null; // should make it faster...

    using (var newStream = webRequest.GetRequestStream())
    {
        newStream.Write(dataStream, 0, dataStream.Length);
    }
    var webResponse = (HttpWebResponse)webRequest.GetResponse();

    string uri = webResponse.Headers["Location"];

    string result;
    using (var sr = new StreamReader(webResponse.GetResponseStream()))
    {
        result = sr.ReadToEnd();
    }


    return result;
}

サーバーは応答として JSON を送信します。小さな JSON では問題なく動作しますが、大きな JSON をリクエストすると何か問題が発生します。概して、ブラウザに表示されるまでに 1 ~ 2 分かかるものを意味します (Google Chrome、サーバー側の生成時間を含む)。実際には 412KB のテキストです。上記の方法で同じ JSON を要求しようとすると、Web 例外 (タイムアウト) が発生します。タイムアウトを 10 分に変更しました (Chrome の 5 倍以上)。まだ同じ。

何か案は?

編集

これは、MS テクノロジーと関係があるようです。IE では、この JSON も読み込まれません。

4

1 に答える 1