0

Making the request with ajax, takes 13 seconds on Internet Explorer

var start = new Date().getTime();            
var xmlRequest = ""; //XML REQUEST
var xmlHttp=null
try  { xmlHttp=new XMLHttpRequest(); }
catch (e)
{
       try { xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); }
       catch (e) { xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); }
}
var sURL = ""; //DESTINATION URL

xmlHttp.open("POST", sURL, false);
xmlHttp.setRequestHeader("Content-Type","text/xml");
xmlHttp.send(xmlRequest);

var end = new Date().getTime();
var time = end - start;
alert('Execution time: ' + time); // 13 seconds
alert("Response:\n" + xmlHttp.responseText); //XML RESPONSE
xmlHttp.close();

Now, trying server side:

public string MakeWebRequest(string url, string xmlRequest)
{
    try
    {
        string responseContent;
        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
        request.Method = "POST";
        byte[] byteArray = Encoding.UTF8.GetBytes(xmlRequest);
        request.ContentType = "text/xml";
        request.ContentLength = byteArray.Length;

        //request.Proxy = null;
        //request.Proxy = WebRequest.GetSystemWebProxy();
        request.Proxy = System.Net.WebRequest.DefaultWebProxy;

        using (Stream requestStream = request.GetRequestStream())
        {
            requestStream.Write(byteArray, 0, byteArray.Length);
        }        
        using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
        {
            using (Stream responseStream = response.GetResponseStream())
            {
                using (StreamReader sr = new StreamReader(responseStream))
                    responseContent = sr.ReadToEnd();
            }
        }
        return responseContent;
    }
    catch (Exception ex)
    {
        return ex.Message;
    }
}

Same URL and same xml request, it takes 40 seconds to response, why??

Same result with:

request.Proxy = null;

and:

request.Proxy = WebRequest.GetSystemWebProxy();

and:

request.Proxy = System.Net.WebRequest.DefaultWebProxy;

and:

<system.net>
  <defaultProxy enabled="false">
    <proxy/>
    <bypasslist/>
    <module/>
  </defaultProxy>
</system.net>

and:

<system.net>
  <connectionManagement>
     <add address="*" maxconnection="65000" />
  </connectionManagement>
</system.net>

tks for any help!

Elton Santana
  • 950
  • 3
  • 11
  • 22

1 Answers1

0

OMFG! I finally found the solution! I used wireshark to view the request headers. HttpWebRequest adds "Expect: 100- continue" by default. I had to remove the parameter to work!

request.ServicePoint.Expect100Continue = false;
Elton Santana
  • 950
  • 3
  • 11
  • 22