Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.
Keywords: iUrlOpen iHttpOpen Error 404 File Not Found
If you insist on using iUrlOpen, it gets a little more complicated. You will have to know some real information about the page that can be returned upon success or upon failure.
iUrlOpen will return the datahandle of zero if it encounters a Wininet error (i.e., 12007). To capture that WinInet error, you can use iGetLastError, but this will not tell you whether or not the page returned is valid or not.
AddExtender("WWINT34i.DLL") tophandle=iBegin(0,"","") datahandle=iUrlOpen(tophandle,"http://xxx.yyy.com"); if datahandle == 0 err=iGetLastError() Message("WinInet Error",err) iClose(tophandle) exit endif iClose(tophandle) exit
If you want to check the page itself, to make sure it's the page you're thinking it is, and not, for exampe, a 'File Not Found' page, you will need to actually read the file data. Then either search for the text you're expecting in the webpage, *OR* maybe search for the text in the 404 message set up for that server.
Note: Different servers can return any kind of 404 message....
This example will search for a 'File Not found' message.
AddExtender("WWINT34i.DLL") tophandle=iBegin(0,"","") datahandle=iUrlOpen(tophandle,"http://www.windowware.com/asldalsd/lghjghj");BAD URL if datahandle == 0 err=iGetLastError() Message("Wininet Error",err) iClose(tophandle) exit endif ;Make sure to allocate large enough buffer to hold the entire file size=10000 buf=BinaryAlloc(size) ;Get address of buffer bufaddr=IntControl (42, buf, 0, 0, 0) BinaryEodSet(buf, size) iReadDataBuf(datahandle,bufaddr,size) ;str=BinaryPeekStr(buf, 0, size) ;message("Contents of Buffer",str) ret =BinaryIndexEx(buf, 0, "File Not Found", @FWDSCAN, @FALSE) if ret != -1 Message("404","File Not Found") Endif iClose(datahandle) iClose(tophandle) Message("All","Done") exit
Article ID: W14556
Filename: Check if iUrlOpen returns what your expecting.txt
File Created: 2017:07:28:12:58:45
Last Updated: 2001:10:05:09:27:38