WinBatch® Technical Support Forum

Archived Boards => WinBatch Script Exchange => Topic started by: dmsimmonds on June 10, 2014, 11:17:24 AM

Title: HTTPOpen does not return 404, Page Not Found
Post by: dmsimmonds on June 10, 2014, 11:17:24 AM
I'm writting a monitor program to see if our web server is ready to accept request by trying to resolve a URL of a known page. If the page is not found, then my program would send messages. Trying to use HTTPOpen() and never receive the 404 that I expected. Here is the test script.
   tophandle=iBegin(0,"","")
   connecthandle=iHostConnect(tophandle, ThisHost,@HTTP,"", "")
   datahandle=iHttpInit(connecthandle, "GET", Object, "",0)
   If datahandle==0
      err=iGetLastError()
      Message("Last Error",err)
      iClose(tophandle)
      Exit
   EndIf
   myheader=StrCat("user_process: My cool app", @CRLF, "app_version: 12.0")
   rslt=iHttpOpen(datahandle, "" , 0, 0)
   Message("HTTPGet", "Response Code = %rslt%")
   If rslt=="ERROR" || rslt!=200
      If rslt == "ERROR"
         errstr = "WinInet Error"
         rslt = iGetLastError()
      Else
         errstr = "HTTP Error"
      EndIf
      Message(errstr,rslt)
      iClose(tophandle)
      Exit
   EndIf
   xx=iReadData(datahandle, StrCat(ProgramPath, "HTTPGet.txt"))
   iClose(datahandle)
   iClose(connecthandle)
   iClose(tophandle)
   Message("All","Done")
Exit

Is there a better way to do this?
Title: Re: HTTPOpen does not return 404, Page Not Found
Post by: JTaylor on June 10, 2014, 11:34:53 AM
Not sure if this applies in your situation but if your webserver has a custom error page defined you will not get a 404 because it redirects to the custom page so, in practical terms, it never has a page that doesn't exist.  Hope this makes sense.

The other question is, what do you get as a response to HTTPOpen?

Jim
Title: Re: HTTPOpen does not return 404, Page Not Found
Post by: dmsimmonds on June 10, 2014, 11:52:59 AM
There is no custome error page, in fact, if i use a browser with the same URL I dod get the 404, Page Not Found. The data I get usinf the iReadData() is
<script src='Login.jsgz'></script>

I get a 200 Response code.
Title: Re: HTTPOpen does not return 404, Page Not Found
Post by: Deana on June 10, 2014, 02:48:55 PM
Cross posted topic. Please only post questions to one board. See my response to this topic here: http://forum.winbatch.com/index.php?topic=967.msg4270.