JScript code:
var resultXML = '';
var Timeout = 20; // set timeout to 20 seconds
var postURL = 'http://someurl.com/page.asp';
var postData = xmlDocument.xml;
var httpRequest = Server.CreateObject("WinHttp.WinHttpRequest.5");
httpRequest.SetTimeouts(Timeout * 1000, Timeout * 1000, Timeout * 1000,
Timeout * 1000);
httpRequest.Open("POST", postURL, false);
httpRequest.SetRequestHeader("Content-Type", "text/xml");
httpRequest.SetRequestHeader("Content-Length", postData.length);
try
{
httpRequest.Send(postData);
if (httpRequest.Status == 200)
{
resultXML = httpRequest.ResponseText;
}
else
{
resultXML = '<error status="' + httpRequest.Status + '" status_text="' +
httpRequest.StatusText + '"/>';
}
}
catch (err)
{
resultXML = '<error number="' + err.number + '" description="' +
err.description + '"/>';
}
return resultXML;
Encountering the "connection could not be established" error when the target
server is under heavy load is not unexpected. Your application will need to
deal with the situation that the server is temporarily not responding.
One possible workaround (although not very satisfactory): upon receiving
this error, pause for a short delay (perhaps two seconds) and then retry the
request.
Are the requests (for 'http://someurl.com/page.asp') being sent back to the
same server machine, or are they going to a different server machine? Care
must be taken when sending requests to ASP pages back on the same machine;
see KB article Q316451:
INFO: Do Not Send ServerXMLHTTP or WinHTTP Requests to the Same Server
http://support.microsoft.com/default.aspx?scid=KB;en-us;316451
I also recommend specifying a -1 (which means infinite) timeout value for
host name resolving:
httpRequest.SetTimeouts(-1, Timeout * 1000, Timeout * 1000, Timeout *
1000);
Supporting a DNS name resolution timeout is very expensive in terms of
resources, and offers little benefit. On Windows NT 4.0 SP4 and later, the
DNS resolver in the operating system will implement a timeout (of 15
seconds) regardless of WinHTTP's timeout setting.
One additional minor note about your code: you do not need to set the
Content-Length request header; the WinHttpRequest object will take care of
this automatically.
Regards,
Stephen Sulzer
Microsoft Corporation
This posting is provided "AS IS" with no warranties, and confers no rights.
"Barry D. Flinn" <no...@nowhere.org> wrote in message
news:uu9S3MumCHA.216@TK2MSFTNGP09...
"Stephen Sulzer [Microsoft]" <ssu...@online.microsoft.com> wrote in message
news:um55tGanCHA.1612@TK2MSFTNGP10...