This is Interesting: Free Magazines for Graphics designers and webmasters  


Home > Archive > Microsoft XML > March 2005 > XMLHTTP - Sending multiple requests via a single HTTP 1.1 connection





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author XMLHTTP - Sending multiple requests via a single HTTP 1.1 connection
Daniel Malcolm

2005-03-15, 6:48 pm

I am using the XMLHTTP object to connect to an SMS gateway URL to send SMS
messages. I need to send messages to multiple phones.

The documentation for the gateway (
http://www.mxtelecom.com/uk/index.j...s/http/send#get ) includes
the following:

<snip>
HTTP/1.1 is enabled so, if sending multiple packets, the TCP/IP connection
should be kept open between requests. If sending message with a high
transmission rate is required, then several persistant HTTP/1.1 connections
should be used concurrently (perhaps 3 or 4). Pipelining requests (ala
Mozilla) is supported but encouraged only where necessary (ie with high
message rates and large latency between customer and MX Telecom).
</snip>

This suggests that I can keep a connection open and send multiple requests,
thus avoiding the handshaking and other negotiation required when connecting
to the remote server. However I'm not sure whether I can keep a connection
open when using XMLHTTP.

My code currently runs as follows:

Set objXmlHttp = New MSXML.XMLHTTPRequest
For Each strPhone In arrPhone
strPostData= "to=" & strPhone & ".. etc etc "
objXmlHttp.Open "POST", [MXTelecomURL], False, strMXTelecomUID,
strMXTelecomPWD
objXmlHttp.setRequestHeader "Content-type",
"application/x-www-form-urlencoded"
objXmlHttp.Send vQueryString
End If
Next

I'm not sure what is happening behind the scenes here, but it takes about 30
seconds to loop through an array of 10 numbers, so I suspect that a new
connection is created each time.

Do I need to work at a lower TCP/IP level and work directly with http
headers etc? Any suggestions appreciated.

Thanks

Daniel





Neil Smith [MVP Digital Media]

2005-03-15, 6:48 pm

I would also try sending the objXmlHttp.setRequestHeader header
Connection: Keep-Alive string, and see if that helps. Any HTTP/1.1
compliant web server should hold that connection up for at least a
few seconds to allow for further requests.

Have a look at this random webpage to see what I mean :
http://perlmonks.thepen.com/83791.html

But I suppose one possible drawback is you've got all that in a loop,
and I don't think you can send "headers" once you've sent content.
That is, after your POST body, you won't be able to send further
headers (such as the content-type you have there), at least not in
compliance with HTTP spec.

HTH
Cheers -Neil

On Tue, 15 Mar 2005 14:10:19 -0000, "Daniel Malcolm"
<daniel.malcolm@nup.jpigroup.com> wrote:

>I am using the XMLHTTP object to connect to an SMS gateway URL to send SMS
>messages. I need to send messages to multiple phones.
>
>The documentation for the gateway (
>http://www.mxtelecom.com/uk/index.j...s/http/send#get ) includes
>the following:
>
><snip>
>HTTP/1.1 is enabled so, if sending multiple packets, the TCP/IP connection
>should be kept open between requests. If sending message with a high
>transmission rate is required, then several persistant HTTP/1.1 connections
>should be used concurrently (perhaps 3 or 4). Pipelining requests (ala
>Mozilla) is supported but encouraged only where necessary (ie with high
>message rates and large latency between customer and MX Telecom).
></snip>
>
>This suggests that I can keep a connection open and send multiple requests,
>thus avoiding the handshaking and other negotiation required when connecting
>to the remote server. However I'm not sure whether I can keep a connection
>open when using XMLHTTP.
>
>My code currently runs as follows:
>
>Set objXmlHttp = New MSXML.XMLHTTPRequest
>For Each strPhone In arrPhone
> strPostData= "to=" & strPhone & ".. etc etc "
> objXmlHttp.Open "POST", [MXTelecomURL], False, strMXTelecomUID,
>strMXTelecomPWD
> objXmlHttp.setRequestHeader "Content-type",
>"application/x-www-form-urlencoded"
> objXmlHttp.Send vQueryString
> End If
> Next
>
>I'm not sure what is happening behind the scenes here, but it takes about 30
>seconds to loop through an array of 10 numbers, so I suspect that a new
>connection is created each time.
>
>Do I need to work at a lower TCP/IP level and work directly with http
>headers etc? Any suggestions appreciated.
>
>Thanks
>
>Daniel
>
>
>
>


Nesho Neshev [MSFT]

2005-03-16, 11:21 pm

Hello Daniel,



I believe XMLHTTP uses WinInet and not WinHhttp. Will you be able to switch
to ServerXMLHTTP? It uses WinHttp and will let you take a WinHttp trace:

http://msdn.microsoft.com/library/e....asp?frame=true



By default WinHttp will send HTTP/1.1 request and will keep the connections
alive. If the server doesn't close the connection it will go into a global
connection pool and will be reused for the next request to the same server.



From the trace file you should be able to verify that the connections are
kept alive. You should able be able to see whether the delay is really due
to the connection setup or because the server is responding slowly.



Hope this helps,



-Nesho Neshev [MSFT]



This posting is provided "AS IS" with no warranties, and confers no rights.





"Daniel Malcolm" <daniel.malcolm@nup.jpigroup.com> wrote in message
news:OBb1RjWKFHA.2800@TK2MSFTNGP10.phx.gbl...
> I am using the XMLHTTP object to connect to an SMS gateway URL to send SMS
> messages. I need to send messages to multiple phones.
>
> The documentation for the gateway (
> http://www.mxtelecom.com/uk/index.j...s/http/send#get ) includes
> the following:
>
> <snip>
> HTTP/1.1 is enabled so, if sending multiple packets, the TCP/IP connection
> should be kept open between requests. If sending message with a high
> transmission rate is required, then several persistant HTTP/1.1

connections
> should be used concurrently (perhaps 3 or 4). Pipelining requests (ala
> Mozilla) is supported but encouraged only where necessary (ie with high
> message rates and large latency between customer and MX Telecom).
> </snip>
>
> This suggests that I can keep a connection open and send multiple

requests,
> thus avoiding the handshaking and other negotiation required when

connecting
> to the remote server. However I'm not sure whether I can keep a connection
> open when using XMLHTTP.
>
> My code currently runs as follows:
>
> Set objXmlHttp = New MSXML.XMLHTTPRequest
> For Each strPhone In arrPhone
> strPostData= "to=" & strPhone & ".. etc etc "
> objXmlHttp.Open "POST", [MXTelecomURL], False, strMXTelecomUID,
> strMXTelecomPWD
> objXmlHttp.setRequestHeader "Content-type",
> "application/x-www-form-urlencoded"
> objXmlHttp.Send vQueryString
> End If
> Next
>
> I'm not sure what is happening behind the scenes here, but it takes about

30
> seconds to loop through an array of 10 numbers, so I suspect that a new
> connection is created each time.
>
> Do I need to work at a lower TCP/IP level and work directly with http
> headers etc? Any suggestions appreciated.
>
> Thanks
>
> Daniel
>
>
>
>
>



Michael Shutt

2005-03-17, 6:44 pm

Hi Nesho,

I am trying to use WinHTTP and ServerXMLHTTP with a series of requests to an
NTLM authenticated connection and I cannot seem to get either one to reuse
the connection. My test code looks like this:

Set oHttp = New WinHttp.WinHttpRequest

oHttp.Open "GET", URL, False
oHttp.SetAutoLogonPolicy AutoLogonPolicy_Always
oHttp.Send

oHttp.Open "GET", URL, False
oHttp.SetAutoLogonPolicy AutoLogonPolicy_Always
oHttp.Send

oHttp.Open "GET", URL, False
oHttp.SetAutoLogonPolicy AutoLogonPolicy_Always
oHttp.Send

As you can see, the same request executes three consecutive times. When I
look at the IIS log, I expect to see a total of 4 entries, an initial
request with a 401 return (which prompts the http client to provide
credentials), followed by 3 successful requests. Instead I see 6 total
requests, like the following:

2005-03-17 21:52:27 10.204.1.31 - 10.204.1.6 8080 GET /Echo.asp - 401
Mozilla/4.0+(compatible;+Win32;+WinHttp.WinHttpRequest.5)
2005-03-17 21:52:27 10.204.1.31 domain\user 10.204.1.6 80 GET /Echo.asp -
200 Mozilla/4.0+(compatible;+Win32;+WinHttp.WinHttpRequest.5)
2005-03-17 21:52:27 10.204.1.31 - 10.204.1.6 8080 GET /Echo.asp - 401
Mozilla/4.0+(compatible;+Win32;+WinHttp.WinHttpRequest.5)
2005-03-17 21:52:27 10.204.1.31 domain\user 10.204.1.6 80 GET /Echo.asp -
200 Mozilla/4.0+(compatible;+Win32;+WinHttp.WinHttpRequest.5)
2005-03-17 21:52:27 10.204.1.31 - 10.204.1.6 8080 GET /Echo.asp - 401
Mozilla/4.0+(compatible;+Win32;+WinHttp.WinHttpRequest.5)
2005-03-17 21:52:27 10.204.1.31 domain\user 10.204.1.6 80 GET /Echo.asp -
200 Mozilla/4.0+(compatible;+Win32;+WinHttp.WinHttpRequest.5)

Am I missing something in my code? Any recommendations on what to look for
in the WinHttp trace files?

Mike

"Nesho Neshev [MSFT]" <neshones@online.microsoft.com> wrote in message
news:OcW80YoKFHA.2764@tk2msftngp13.phx.gbl...
> Hello Daniel,
>
>
>
> I believe XMLHTTP uses WinInet and not WinHhttp. Will you be able to

switch
> to ServerXMLHTTP? It uses WinHttp and will let you take a WinHttp trace:
>
>

http://msdn.microsoft.com/library/e....asp?frame=true
>
>
>
> By default WinHttp will send HTTP/1.1 request and will keep the

connections
> alive. If the server doesn't close the connection it will go into a global
> connection pool and will be reused for the next request to the same

server.
>
>
>
> From the trace file you should be able to verify that the connections are
> kept alive. You should able be able to see whether the delay is really due
> to the connection setup or because the server is responding slowly.
>
>
>
> Hope this helps,
>
>
>
> -Nesho Neshev [MSFT]
>
>
>
> This posting is provided "AS IS" with no warranties, and confers no

rights.
>
>
>
>
>
> "Daniel Malcolm" <daniel.malcolm@nup.jpigroup.com> wrote in message
> news:OBb1RjWKFHA.2800@TK2MSFTNGP10.phx.gbl...
SMS[color=darkred]
includes[color=darkred]
connection[color=darkred]
> connections
> requests,
> connecting
connection[color=darkred]
about[color=darkred]
> 30
>
>



Nesho Neshev [MSFT]

2005-03-20, 6:47 pm

Hi Michael,



Unfortunately WinHttp doesn't log the fact that it reusing a connection but
you can still get some clues from the trace file. If the server does not
send "Connection: Close" header and if WinHttp drains all the response data
before sending the next request then it will most likely reuse the
connection.



The best way to tell if the connection is reused is to capture the network
traffic (using Network Monitor or similar tool):

http://msdn.microsoft.com/library/d...monitor_2_0.asp



From there you will be able to see if a new TCP connection is established
and if each subsequent HTTP request reuses the same TCP source port.



The authentication in your IIS log below takes only one roundtrip so it is
probably Negotiate/Kerberos and not NTLM. What is the value of the
"Authorization:" header that WinHttp is sending? Does it start with "NTLM"
or "Negotiate"?


Hope this helps,

-Nesho Neshev [MSFT]

This posting is provided "AS IS" with no warranties, and confers no rights.


"Michael Shutt" <mshutt@nospam_advectis.com> wrote in message
news:euuFKyzKFHA.3064@TK2MSFTNGP12.phx.gbl...
> Hi Nesho,
>
> I am trying to use WinHTTP and ServerXMLHTTP with a series of requests to

an
> NTLM authenticated connection and I cannot seem to get either one to reuse
> the connection. My test code looks like this:
>
> Set oHttp = New WinHttp.WinHttpRequest
>
> oHttp.Open "GET", URL, False
> oHttp.SetAutoLogonPolicy AutoLogonPolicy_Always
> oHttp.Send
>
> oHttp.Open "GET", URL, False
> oHttp.SetAutoLogonPolicy AutoLogonPolicy_Always
> oHttp.Send
>
> oHttp.Open "GET", URL, False
> oHttp.SetAutoLogonPolicy AutoLogonPolicy_Always
> oHttp.Send
>
> As you can see, the same request executes three consecutive times. When I
> look at the IIS log, I expect to see a total of 4 entries, an initial
> request with a 401 return (which prompts the http client to provide
> credentials), followed by 3 successful requests. Instead I see 6 total
> requests, like the following:
>
> 2005-03-17 21:52:27 10.204.1.31 - 10.204.1.6 8080 GET /Echo.asp - 401
> Mozilla/4.0+(compatible;+Win32;+WinHttp.WinHttpRequest.5)
> 2005-03-17 21:52:27 10.204.1.31 domain\user 10.204.1.6 80 GET /Echo.asp -
> 200 Mozilla/4.0+(compatible;+Win32;+WinHttp.WinHttpRequest.5)
> 2005-03-17 21:52:27 10.204.1.31 - 10.204.1.6 8080 GET /Echo.asp - 401
> Mozilla/4.0+(compatible;+Win32;+WinHttp.WinHttpRequest.5)
> 2005-03-17 21:52:27 10.204.1.31 domain\user 10.204.1.6 80 GET /Echo.asp -
> 200 Mozilla/4.0+(compatible;+Win32;+WinHttp.WinHttpRequest.5)
> 2005-03-17 21:52:27 10.204.1.31 - 10.204.1.6 8080 GET /Echo.asp - 401
> Mozilla/4.0+(compatible;+Win32;+WinHttp.WinHttpRequest.5)
> 2005-03-17 21:52:27 10.204.1.31 domain\user 10.204.1.6 80 GET /Echo.asp -
> 200 Mozilla/4.0+(compatible;+Win32;+WinHttp.WinHttpRequest.5)
>
> Am I missing something in my code? Any recommendations on what to look

for
> in the WinHttp trace files?
>
> Mike
>
> "Nesho Neshev [MSFT]" <neshones@online.microsoft.com> wrote in message
> news:OcW80YoKFHA.2764@tk2msftngp13.phx.gbl...
> switch
>

http://msdn.microsoft.com/library/e....asp?frame=true
> connections
global[color=darkred]
> server.
are[color=darkred]
due[color=darkred]
> rights.
> SMS
> includes
> connection
high[color=darkred]
> connection
strMXTelecomUID,[color=darkred]
> about
new[color=darkred]
>
>



Sponsored Links


Copyright 2003 - 2008 forum4designers.com  Software forum  Computer Hardware reviews