Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.
KEYWORDS: 302 redirect HTTP_STATUS_REDIRECT
Question: is there any way to determine the URL of the page you have been sent to? These frequently contain useful info like session ids.
Possible but difficult workaround: You could attempt to make a DllCall to HttpOpenRequest and set the flag "INTERNET_FLAG_NO_AUTO_REDIRECT". This tells Wininet to not perform any automatically handling of redirected URLs. You would have to implement it for yourself with the benefit of getting the "real" URL -- look for the "Location" HTTP header field in the first HTTP response. If you do set the flag "INTERNET_FLAG_NO_AUTO_REDIRECT" you have to check the HTTP status code for:
HTTP_STATUS_MOVED /* 301 -- object permanently moved */ HTTP_STATUS_REDIRECT /* 302 -- object temporarily moved */ HTTP_STATUS_REDIRECT_METHOD /* 303 -- redirection w/ new access method */If one of those HTTP status codes apply, you have to look for the HTTP header field "Location" (iHttpHeaders) to get the "real" URL. To get that "real" URL, you have to perform a new HTTP request with that URL.
You might be able to obtain that information using Internet Explorers object model. but this would require you to rewrite your code.
INTERNET_FLAG_NO_AUTO_REDIRECT = 2097152 datahandle = DllCall("WinInet.dll", long:"HttpOpenRequestA", long:connecthandle, lpstr:"GET", lpstr:geturl, lpstr:"HTTP/1.1", lpstr:"", long:0, long:INTERNET_FLAG_NO_AUTO_REDIRECT, long:0)If you're using any of the flags supported by iHttpInit you'll need to look up the appropriate values and OR them in with INTERNET_FLAG_NO_AUTO_REDIRECT.
If you're trying to do this for an https resource you need to make two changes:
(1) change the flag to INTERNET_FLAG_NO_AUTO_REDIRECT | INTERNET_FLAG_SECURE
where the latter value is 8388608, and
(2) strip the first character from connecthandle - WinBatch prepends the handle with an S, presumably to let iHttpInit know that it needs to set INTERNET_FLAG_SECURE.
Here is a UDF I created that can be used to replace the iHttpInit statement:
#DefineFunction iHttpInitNoRedir (connecthandle, verb, object, referrer, flags) INTERNET_FLAG_NO_AUTO_REDIRECT = 2097152 INTERNET_FLAG_SECURE = 8388608 flags = flags | INTERNET_FLAG_NO_AUTO_REDIRECT If StrSub(connecthandle, 1, 1) == "S" connecthandle = StrSub(connecthandle, 2, -1) flags = flags | INTERNET_FLAG_SECURE EndIf Return DllCall("WinInet.dll", long:"HttpOpenRequestA", long:connecthandle, lpstr:verb, lpstr:object, lpstr:"HTTP/1.1", lpstr:referrer, long:0, long:flags, long:0) #EndFunction
Article ID: W16886
File Created: 2017:07:28:13:58:46
Last Updated: 2007:07:03:14:26:42