Discussion:
HttpSendRequestEx returns success even though it should fail
(too old to reply)
ploskinj
2006-12-04 13:17:31 UTC
Permalink
Hi, I'm having a weird problem with WinInet in Delphi. We use
HttpSendRequestEx to communicate with servlets. The error handling for
this is weird, for some reason if the servlets are down or if they
don't exist on our server at all HttpSendRequestEx still succeeds and
GetQueryInfo returns 0.

Is there a better or different way to look for that kind of error?

Thanks!
Vladimir Scherbina
2006-12-04 14:56:56 UTC
Permalink
If target is offline then HttpSendRequestEx/HttpSendRequest should definitly
return FALSE. Can you put simplest code that causes the problem and specify
the IE version? Better to attach source file to post.
--
Vladimir (Windows SDK MVP)
http://msmvps.com/blogs/v_scherbina/
Post by ploskinj
Hi, I'm having a weird problem with WinInet in Delphi. We use
HttpSendRequestEx to communicate with servlets. The error handling for
this is weird, for some reason if the servlets are down or if they
don't exist on our server at all HttpSendRequestEx still succeeds and
GetQueryInfo returns 0.
Is there a better or different way to look for that kind of error?
Thanks!
ploskinj
2006-12-04 16:08:59 UTC
Permalink
Thanks for the reply, I'm working on a Delphi application but if that
has something to do with the version of WinInet, we all have IE6 on our
machines now.

I can't post a lot of code, I think this includes most of what might be
causing the problem, do you see anything odd here?

if (opReqSession <> nil) then
InternetCloseHandle(opReqSession);
result:=HttpOpenRequest(opHttpSession, PChar(sVerb), PChar(sUrl),
nil, nil, nil, INTERNET_FLAG_SECURE or INTERNET_FLAG_KEEP_CONNECTION or
INTERNET_FLAG_NO_CACHE_WRITE or INTERNET_FLAG_IGNORE_CERT_CN_INVALID,
0);

Later we use this function

if (bNewRequest) or (opReqSession = nil) then
opReqSession:=GetRequest(sUrl, sVerb);

iLastError:=0;
sHeader:=FormatHeader(ssHeader);

FillChar(OutBuffer, SizeOf(OutBuffer), 0);
OutBuffer.dwStructSize:=SizeOf(OutBuffer);
OutBuffer.lpcszHeader:=PChar(sHeader);
OutBuffer.dwHeadersLength:=Length(sHeader);
OutBuffer.dwBufferTotal:=Length(aData);

if HttpSendRequestEx(opReqSession, @OutBuffer, nil, HSR_INITIATE or
HSR_SYNC, 0) then
begin

// Some stuff

if iLastError = 0 then
begin
if not HttpEndRequest(opReqSession, nil, HSR_SYNC, 0) then
begin
iLastError:=GetLastError;
if iLastError = 12030 then
begin
Self.AddLog('Http Error Encountered, ignoring...
('+IntToStr(iLastError)+')');
iLastError:=0;
end;
end;
end;


end
else
iLastError:=GetLastError;
if iLastError <> 0 then
begin
iWebError:=GetQueryInfo(opReqSession);

Self.AddLog('Http Error Encountered, retrying...
('+IntToStr(iLastError)+', '+IntToStr(iWebError)+')');
SendRequest(sUrl, sVerb, ssHeader, aData, false);
end;
else
raise TtcException.Create(ClassType, 'SendRequest', 'Error during
request ('+IntToStr(iLastError)+', '+IntToStr(iWebError)+')');
end;
end;
end;

end
else
iLastError:=GetLastError;
if iLastError <> 0 then
begin
iWebError:=GetQueryInfo(opReqSession);
case iWebError div 100 of
4, 5:
// 401, //
// 500, // internal server error
// 502, // bad gateway
// 503, // service unavailable
// 504: // gateway timeout
begin
Self.AddLog('Http Error Encountered, retrying...
('+IntToStr(iLastError)+', '+IntToStr(iWebError)+')');
SendRequest(sUrl, sVerb, ssHeader, aData, false);
end;
else
raise TtcException.Create(ClassType, 'SendRequest', 'Error during
request ('+IntToStr(iLastError)+', '+IntToStr(iWebError)+')');
end;
end;
end;

I really appreciate your help with this.
Vladimir Scherbina
2006-12-05 11:24:51 UTC
Permalink
Sorry, I misunderstood your first post. I read "servers" instead of
"servlets". In case when servlet is absent it's up to server what to return.
Typically, 404 should be returned. I guess you need analyze logs of your
Tomcat (are you using Tomcat as server?).

In case when something is not present on web server HttpSendRequest should
return TRUE - it's normal behavior for function. It returnes FALSE in case
when server is down - that's what I thought was in your case.

Anyway, try to test code attached to this post. It gets a page from cnn.com
and just gathers the status code. Try to use it for your servlets, I wonder,
what status will you get when there will be no servlet on a webserver?
--
Vladimir (Windows SDK MVP)
http://msmvps.com/blogs/v_scherbina/
Loading...