1
내 방법은 다음과 같습니다WebRequest 클래스 매우 느린
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에서는 잘 작동하지만 큰 것을 요청할 때 문제가 발생합니다. 대형 광고는 브라우저에 표시되는 데 1 ~ 2 분이 소요되는 것을 의미합니다 (Google 크롬, 서버 측 생성 시간 포함). 사실 412KB의 텍스트입니다. 위의 메서드를 사용하여 동일한 JSON을 요청하려고하면 웹 예외 (시간 초과)가 발생합니다. 타임 아웃을 10 분으로 변경했습니다 (크롬보다 적어도 5 배 이상). 여전히 동일합니다.
아이디어가 있으십니까?
편집
이 MS 기술을 함께 할 수있는 뭔가를 갖고있는 것 같아요. IE에서는이 JSON도로드되지 않습니다.