Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

WinHttp.WinHttpRequest.5 problem

586 views
Skip to first unread message

Barry D. Flinn

unread,
Dec 3, 2002, 10:49:49 AM12/3/02
to
I have a problem with an ASP page on an NT 4.0 machine. The majority of the
time, this page works without a problem. (There are actually several pages
which do similar things.) However, I will occasionally get this error:
"-2147012867 A connection with the server could not be established". When I
get this, it appears to come in spurts, i.e. I will get this error on more
than just the original page that caused it. It seems to only happen when
the server is under a higher than usual load. I have included the piece of
code where the problem occurs below. Any insight would be greatly
appreciated.
.
Thanks

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;


Stephen Sulzer [Microsoft]

unread,
Dec 6, 2002, 10:35:29 PM12/6/02
to

Hello,

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...

Barry D. Flinn

unread,
Dec 9, 2002, 2:10:53 PM12/9/02
to
Thanks for your response, but it doesn't exactly help with my problem.
(Which is my own fault, I may not have been clear enough.) The server that
is under load is the one doing the call, not the one receiving the call.
The call is being made to a third party, which is not even in our domain.
i.e. The call to http://someurl.org/foo.asp will fail, and
http://someotherurl.com/bar.asp will also fail when called from
http://myhost.com, but http://myhost.com is the server under a higher load
that usual.


"Stephen Sulzer [Microsoft]" <ssu...@online.microsoft.com> wrote in message
news:um55tGanCHA.1612@TK2MSFTNGP10...

0 new messages