AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

[StdLib] WININET Functions & UrlGetContents

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
ahklerner



Joined: 26 Jun 2006
Posts: 1249
Location: USA

PostPosted: Wed Jul 09, 2008 11:00 pm    Post subject: [StdLib] WININET Functions & UrlGetContents Reply with quote

I wrapped the WinInet.dll functions to be StdLib compatible.

The WININET lib includes the functionality above as well as the FTP functions that were spread across the forum. This allows a single include that can be utilized for HTTP and FTP communication.

edit:
WININET_UrlGetContents() now Supports SSL.

edit:
Changed name to just UrlGetContents as it is not really a WININET function.

edit:
added api

Here it is :
Code:

; ==========
; Origional FTP Functions by Olfen & Andreone
; See the following post:
; http://www.autohotkey.com/forum/viewtopic.php?t=10393
; ==========
; WININET_UrlGetContents() is based on heresy & DerRaphael's script here:
; http://www.autohotkey.com/forum/viewtopic.php?t=33506
; ==========
; by ahklerner
; ==========


WININET_Init(){
   global
   WININET_hModule := DllCall("LoadLibrary", "Str", "WinInet.Dll")
}

WININET_UnInit(){
   global
   DllCall("FreeLibrary", "UInt", WININET_hModule)
}

WININET_InternetOpenA(lpszAgent,dwAccessType=1,lpszProxyName=0,lpszProxyBypass=0,dwFlags=0){
   ;http://msdn.microsoft.com/en-us/library/aa385096(VS.85).aspx
   return DllCall("WinINet\InternetOpenA"
            , "Str"      ,lpszAgent
            , "UInt"   ,dwAccessType
            , "Str"      ,lpszProxyName
            , "Str"      ,lpszProxyBypass
            , "Uint"   ,dwFlags )
}

WININET_InternetConnectA(hInternet,lpszServerName,nServerPort=80,lpszUsername=""
               ,lpszPassword="",dwService=3,dwFlags=0,dwContext=0){
   ;http://msdn.microsoft.com/en-us/library/aa384363(VS.85).aspx
   ; INTERNET_SERVICE_FTP = 1
   ; INTERNET_SERVICE_HTTP = 3
   return DllCall("WinINet\InternetConnectA"
            , "uInt"   ,hInternet
            , "Str"      ,lpszServerName
            , "Int"      ,nServerPort
            , "Str"      ,lpszUsername
            , "Str"      ,lpszPassword
            , "uInt"   ,dwService
            , "uInt"   ,dwFlags
            , "uInt*"   ,dwContext )
}

WININET_HttpOpenRequestA(hConnect,lpszVerb,lpszObjectName,lpszVersion="HTTP/1.1"
            ,lpszReferer="",lplpszAcceptTypes="",dwFlags=0,dwContext=0){
   ;http://msdn.microsoft.com/en-us/library/aa384233(VS.85).aspx
   return DllCall("WinINet\HttpOpenRequestA"
            , "uInt"   ,hConnect
            , "Str"      ,lpszVerb
            , "Str"      ,lpszObjectName
            , "Str"      ,lpszVersion
            , "Str"      ,lpszReferer
            , "Str"      ,lplpszAcceptTypes
            , "uInt"   ,dwFlags
            , "uInt"   ,dwContext )
}

WININET_HttpSendRequestA(hRequest,lpszHeaders="",lpOptional=""){
   ;http://msdn.microsoft.com/en-us/library/aa384247(VS.85).aspx
   return DllCall("WinINet\HttpSendRequestA"
            , "uInt"   ,hRequest
            , "Str"      ,lpszHeaders
            , "uInt"   ,Strlen(lpszHeaders)
            , "Str"      ,lpOptional
            , "uInt"   ,Strlen(lpOptional) )
}

WININET_InternetReadFile(hFile){
   ;http://msdn.microsoft.com/en-us/library/aa385103(VS.85).aspx
   dwNumberOfBytesToRead := 1024**2
   VarSetCapacity(lpBuffer,dwNumberOfBytesToRead,0)
   VarSetCapacity(lpdwNumberOfBytesRead,4,0)
   Loop {
      if DllCall("wininet\InternetReadFile","uInt",hFile,"uInt",&lpBuffer
            ,"uInt",dwNumberOfBytesToRead,"uInt",&lpdwNumberOfBytesRead ) {
         VarSetCapacity(lpBuffer,-1)
         TotalBytesRead := 0
         Loop, 4
            TotalBytesRead += *(&lpdwNumberOfBytesRead + A_Index-1) << 8*(A_Index-1)
         If !TotalBytesRead
            break
         Else
            Result .= SubStr(lpBuffer,1,TotalBytesRead)
      }
   }
   return Result
}


WININET_FtpCreateDirectoryA(hConnect,lpszDirectory) {
   ;http://msdn.microsoft.com/en-us/library/aa384136(VS.85).aspx
   r := DllCall("wininet\FtpCreateDirectoryA", "uint", hConnect, "str", lpszDirectory)
   If (ErrorLevel or !r)
      Return 0
   else
      Return 1
   }


WININET_FtpRemoveDirectoryA(hConnect,lpszDirectory) {
   ;http://msdn.microsoft.com/en-us/library/aa384172(VS.85).aspx
   r := DllCall("wininet\FtpRemoveDirectoryA", "uint", hConnect, "str", lpszDirectory)
   If (ErrorLevel or !r)
      Return 0
   else
      Return 1
   }

WININET_FtpSetCurrentDirectoryA(hConnect,lpszDirectory) {
   ;http://msdn.microsoft.com/en-us/library/aa384178(VS.85).aspx
   r := DllCall("wininet\FtpSetCurrentDirectoryA", "uint", hConnect, "str", lpszDirectory)
   If (ErrorLevel or !r)
      Return 0
   else
      Return 1
   }

WININET_FtpPutFileA(hConnect,lpszLocalFile, lpszNewRemoteFile="", dwFlags=0,dwContext=0) {
   ;http://msdn.microsoft.com/en-us/library/aa384170(VS.85).aspx
   If lpszNewRemoteFile =
      lpszNewRemoteFile := lpszLocalFile
   r := DllCall("wininet\FtpPutFileA"
         , "uint"   , hConnect
         , "str"      , lpszLocalFile
         , "str"      , lpszNewRemoteFile
         , "uint"   , dwFlags
         , "uint"   , dwContext )
   If (ErrorLevel or !r)
      Return 0
   else
      Return 1
   }

WININET_FtpGetFileA(hConnect,lpszRemoteFile, lpszNewFile="", fFailIfExists=1
            ,dwFlagsAndAttributes=0,dwFlags=0,dwContext=0) {
   ;http://msdn.microsoft.com/en-us/library/aa384157(VS.85).aspx
   If lpszNewFile=
      lpszNewFile := lpszRemoteFile
   r := DllCall("wininet\FtpGetFileA"
         , "uint"   , hConnect
         , "str"      , lpszRemoteFile
         , "str"      , lpszNewFile
         , "int"      , fFailIfExists
         , "uint"   , dwFlagsAndAttributes
         , "uint"   , dwFlags
         , "uint"   , dwContext )
   If (ErrorLevel or !r)
   Return 0
   else
   Return 1
}

WININET_FtpOpenFileA(hConnect,lpszFileName,dwAccess=0x80000000,dwFlags=0,dwContext=0){
   ;http://msdn.microsoft.com/en-us/library/aa384166(VS.85).aspx
   Result := DllCall("wininet\FtpOpenFileA"
         , "uint"   , hConnect
         , "str"      , lpszFileName
         , "uint"   , dwAccess
         , "uint"   , dwFlags
         , "uint"   , dwContext   ) ;dwContext
   If (ErrorLevel or !r)
      Return -1
   Return Result
}

WININET_InternetCloseHandle(hInternet){
   DllCall("wininet\InternetCloseHandle"
         ,  "UInt"   , hInternet   )
}

WININET_FtpGetFileSize(hFile,lpdwFileSizeHigh=0) {
   ;http://msdn.microsoft.com/en-us/library/aa384159(VS.85).aspx
   return DllCall("wininet\FtpGetFileSize"
               , "uint"   , hFile
               , "uint"   , lpdwFileSizeHigh   )
}

WININET_FtpDeleteFileA(hConnect,lpszFileName) {
   ;http://msdn.microsoft.com/en-us/library/aa384142(VS.85).aspx
   r :=  DllCall("wininet\FtpDeleteFileA"
               , "uint"   , hConnect
            , "str"      , lpszFileName)
   If (ErrorLevel or !r)
      Return 0
   else
      Return 1
   }

WININET_FtpRenameFileA(hConnect,lpszExisting, lpszNew) {
   ;http://msdn.microsoft.com/en-us/library/aa384175(VS.85).aspx
   r := DllCall("wininet\FtpRenameFileA"
            , "uint"   , hConnect
            , "str"      , lpszExisting
            , "str"      , lpszNew   )
   If (ErrorLevel or !r)
      Return 0
   else
      Return 1
}

WININET_FindFirstFile(hConnect, lpszSearchFile, ByRef lpFindFileData,dwFlags=0,dwContext=0) {
   ;http://msdn.microsoft.com/en-us/library/aa384146(VS.85).aspx
   SIZE_OF_WIN32_FIND_DATA := ( 4 + (3*8) + (4*4) + (260*4) + (14*4) )
   VarSetCapacity(lpFindFileData, SIZE_OF_WIN32_FIND_DATA, 0)
   hFind := DllCall("wininet\FtpFindFirstFileA"
         , "uint"   , hConnect
         , "str"   , lpszSearchFile
         , "uint"   , &lpFindFileData
         , "uint"   , dwFlags
         , "uint"   , dwContext )

   If(!hFind)
      VarSetCapacity(lpFindFileData, 0)
   Return hFind
}

WININET_FindNextFile(hFind, ByRef lpvFindData) {
;http://msdn.microsoft.com/en-us/library/aa384698(VS.85).aspx
   Return DllCall("wininet\InternetFindNextFileA"
      , "uint", hFind
      , "uint", &lpvFindData)
}


UrlGetContents():
Code:
UrlGetContents(sUrl,sUserName="",sPassword="",sPostData="",sUserAgent="Autohotkey"){
   ; based on heresy & DerRaphael's script here:
   ; http://www.autohotkey.com/forum/viewtopic.php?t=33506
   
   ;default ports
   INTERNET_INVALID_PORT_NUMBER    = 0
   INTERNET_DEFAULT_HTTP_PORT       = 80
   INTERNET_DEFAULT_HTTPS_PORT    = 443
   
   ;ssl flags
   INTERNET_FLAG_SECURE                = 0x00800000
   SECURITY_FLAG_IGNORE_UNKNOWN_CA       = 0x00000100
   SECURITY_FLAG_IGNORE_CERT_CN_INVALID    = 0x00001000
   SECURITY_FLAG_IGNORE_CERT_DATE_INVALID    = 0x00002000
   
   SplitPath,sURL,sFileName,sPath,sExt,sNoExt,sServer
   sProtocol := (RegExMatch(sServer,"(^http://|^ftp://|^https://)",pr)) ? pr1 : "unknown"
   if (sProtocol = "http://"){
      nPort := INTERNET_DEFAULT_HTTP_PORT
      dwFlags = 0
   } else if (sProtocol = "https://") {
      nPort := INTERNET_DEFAULT_HTTPS_PORT
      dwFlags := (INTERNET_FLAG_SECURE|SECURITY_FLAG_IGNORE_CERT_CN_INVALID
         |SECURITY_FLAG_IGNORE_CERT_DATE_INVALID|SECURITY_FLAG_IGNORE_UNKNOWN_CA)
   } else {
      nPort := INTERNET_INVALID_PORT_NUMBER
      dwFlags = 0
   }      
   sPath := RegExReplace(sPath,"\Q" sServer "\E")
   sServerName := (sProtocol!="unknown") ? RegExReplace(sServer,"\Q" sProtocol "\E") : sServer
   sObjectName := sPath . "/" . sFileName
   hInternet := WININET_InternetOpenA(sUserAgent)
   hConnect := WININET_InternetConnectA(hInternet,sServerName,nPort,sUserName,sPassword)
   if sPostData
      sHTTPVerb:="POST", sHeaders:="Content-Type: application/x-www-form-urlencoded"
   else
      sHTTPVerb:="GET", sHeaders:=""
   sVersion:="HTTP/1.1", sReferer:="", sAcceptTypes:=""
   hRequest := WININET_HttpOpenRequestA(hConnect,sHTTPVerb,sObjectName,sVersion,sReferer,sAcceptTypes,dwFlags)
   if WININET_HttpSendRequestA(hRequest,sHeaders,sPostData)
      sData := WININET_InternetReadFile(hRequest)
   WININET_InternetCloseHandle(hRequest)
   WININET_InternetCloseHandle(hInternet)
   WININET_InternetCloseHandle(hConnect)
   return sData
}

A couple test scripts:
Code:

;Get Web Page Contents Test
WININET_Init()
MsgBox % UrlGetContents("http://www.autohotkey.net")
WININET_UnInit()
return

Code:

;FTP Upload-Download Test
WININET_Init()
OnExit, CleanUp

sHost = autohotkey.net
nPort = 21
sUsername = YourUserName
sPassword = YourPassword
sLocalFile = C:\test_word_document.doc
sRemoteFile = /test_word_document.doc
sNewLocalFile = C:\new_test_word_document.doc
fFailIfExists := True ; False to overwrite existing file on download

INTERNET_OPEN_TYPE_DIRECT    = 1
INTERNET_SERVICE_FTP       = 1

; establish connection to FTP server
if hInternet := WININET_InternetOpenA(A_ScriptName,INTERNET_OPEN_TYPE_DIRECT)
   hConnect := WININET_InternetConnectA(hInternet,sHost,nPort,sUserName,sPassword,INTERNET_SERVICE_FTP)
If (ErrorLevel or !hConnect) {
   MsgBox, Error connecting to FTP server.
   ExitApp
   }
MsgBox Connected to Server

;Upload File
if !WININET_FtpPutFileA(hConnect,sLocalFile, sRemoteFile){
   MsgBox, Error uploading file
   ExitApp
   }
MsgBox Upload Complete

; download file
if !WININET_FtpGetFileA(hConnect,sRemoteFile,sNewLocalFile, fFailIfExists){
   MsgBox, Error downloading file
   ExitApp
   }
MsgBox Download Complete

ExitApp

CleanUp:
MsgBox Exiting.
WININET_InternetCloseHandle(hConnect)
WININET_InternetCloseHandle(hInternet)
WININET_UnInit()
ExitApp

api

Code:
/* api for wininet.ahk
WININET_FindNextFile( hFind, lpvFindData )
WININET_FindFirstFile( hConnect, lpszSearchFile, lpFindFileData [ , dwFlags, dwContext ] )
WININET_FtpRenameFileA( hConnect, lpszExisting, lpszNew )
WININET_FtpDeleteFileA( hConnect, lpszFileName )
WININET_FtpGetFileSize( hFile [ , lpdwFileSizeHigh ] )
WININET_InternetCloseHandle( hInternet )
WININET_FtpOpenFileA( hConnect, lpszFileName [ , dwAccess, dwFlags, dwContext ] )
WININET_FtpGetFileA( hConnect, lpszRemoteFile [ , lpszNewFile, fFailIfExists, dwFlagsAndAttributes, dwFlags, dwContext ] )
WININET_FtpPutFileA( hConnect, lpszLocalFile [ , lpszNewRemoteFile, dwFlags, dwContext ] )
WININET_FtpSetCurrentDirectoryA( hConnect, lpszDirectory )
WININET_FtpRemoveDirectoryA( hConnect, lpszDirectory )
WININET_FtpCreateDirectoryA( hConnect, lpszDirectory )
WININET_InternetReadFile( hFile )
WININET_HttpSendRequestA( hRequest [ , lpszHeaders, lpOptional ] )
WININET_HttpOpenRequestA( hConnect, lpszVerb, lpszObjectName [ , lpszVersion, lpszReferer, lplpszAcceptTypes, dwFlags, dwContext ] )
WININET_InternetConnectA( hInternet, lpszServerName [ , nServerPort, lpszUsername, lpszPassword, dwService, dwFlags, dwContext ] )
WININET_InternetOpenA( lpszAgent [ , dwAccessType, lpszProxyName, lpszProxyBypass, dwFlags ] )
WININET_UnInit( )
WININET_Init( )
*/

_________________

ʞɔпɟ əɥʇ ʇɐɥʍ


Last edited by ahklerner on Fri Jul 11, 2008 4:26 am; edited 4 times in total
Back to top
View user's profile Send private message
ahklerner



Joined: 26 Jun 2006
Posts: 1249
Location: USA

PostPosted: Thu Jul 10, 2008 4:53 pm    Post subject: Reply with quote

example for http authentication:
Code:
;Get Web Page Contents Test
;with username and password

WININET_Init()
MsgBox % UrlGetContents("http://www.someserver.com","UserName","Password")
WININET_UnInit()
return


example for ssl:
Code:
;Get Web Page Contents Test
;with ssl

WININET_Init()
MsgBox % UrlGetContents("https://mail.google.com/mail")
WININET_UnInit()
return

_________________

ʞɔпɟ əɥʇ ʇɐɥʍ


Last edited by ahklerner on Fri Jul 11, 2008 12:51 am; edited 2 times in total
Back to top
View user's profile Send private message
ahklerner



Joined: 26 Jun 2006
Posts: 1249
Location: USA

PostPosted: Fri Jul 11, 2008 12:45 am    Post subject: Reply with quote

SSL now works in UrlGetContents()
_________________

ʞɔпɟ əɥʇ ʇɐɥʍ
Back to top
View user's profile Send private message
shajul



Joined: 15 Sep 2006
Posts: 33
Location: India

PostPosted: Fri Jul 11, 2008 9:15 am    Post subject: Good Reply with quote

Good work Smile
Back to top
View user's profile Send private message Yahoo Messenger
heresy



Joined: 11 Mar 2008
Posts: 291

PostPosted: Mon Jul 14, 2008 7:22 am    Post subject: Reply with quote

Nice. it's time to wrap winsock too Laughing
Thanks for wrapping it ahklerner
_________________
Easy WinAPI - Dive into Windows API World
Benchmark your AutoHotkey skills at PlayAHK.com
Back to top
View user's profile Send private message
Fry



Joined: 01 Nov 2007
Posts: 689

PostPosted: Tue Jul 15, 2008 3:55 pm    Post subject: Reply with quote

Can you wrap the Wireless API for me?
_________________
check out my site
www.eliteknifesquad.com
Back to top
View user's profile Send private message
ahklerner



Joined: 26 Jun 2006
Posts: 1249
Location: USA

PostPosted: Wed Jul 16, 2008 12:02 am    Post subject: Reply with quote

sorry, as I said before, I dont have an interest in it.
_________________

ʞɔпɟ əɥʇ ʇɐɥʍ
Back to top
View user's profile Send private message
Fry



Joined: 01 Nov 2007
Posts: 689

PostPosted: Wed Jul 16, 2008 12:41 am    Post subject: Reply with quote

Just a few functions?
_________________
check out my site
www.eliteknifesquad.com
Back to top
View user's profile Send private message
ahklerner



Joined: 26 Jun 2006
Posts: 1249
Location: USA

PostPosted: Wed Jul 16, 2008 1:10 am    Post subject: Reply with quote

well i was (am) bored.
http://www.autohotkey.com/forum/viewtopic.php?t=33726
_________________

ʞɔпɟ əɥʇ ʇɐɥʍ
Back to top
View user's profile Send private message
trialanderror



Joined: 12 Jul 2008
Posts: 3

PostPosted: Thu Jul 24, 2008 1:40 am    Post subject: Can I Pass Referrer this way in your wrapper? Reply with quote

Thanks for the wrapper. One question about setting the referer.

Can I just pass do this?

Code:

UrlGetContents(sUrl,sUserName="",sPassword="",sPostData="",sUserAgent="Autohotkey",sReferer="someurl")


tia
tae
Back to top
View user's profile Send private message
DerRaphael



Joined: 23 Nov 2007
Posts: 604
Location: 127.0.0.1

PostPosted: Fri Jul 25, 2008 9:35 am    Post subject: Reply with quote

hi AHKlerner, hi rest

i thought this lil function might be of interest for u, so i just paste it here:

Code:
WinINet_InternetCrackURL(lpszUrl,arrayName="URL")
{ ; v 0.1 / (w) 25.07.2008 by derRaphael / zLib-Style release
   local hModule, offset_name_length
   hModule := DllCall("LoadLibrary", "Str", "WinINet.Dll")

   ; SetUpStructures for URL_COMPONENTS / needed for InternetCrackURL
   ; http://msdn.microsoft.com/en-us/library/aa385420(VS.85).aspx
   offset_name_length:= "4-lpszScheme-255|16-lpszHostName-1024|28-lpszUserName-1024|"
                    . "36-lpszPassword-1024|44-lpszUrlPath-1024|52-lpszExtrainfo-1024"
   VarSetCapacity(URL_COMPONENTS,60,0)
   ; Struc Size               ; Scheme Size                  ; Max Port Number
   NumPut(60,URL_COMPONENTS,0), NumPut(255,URL_COMPONENTS,12), NumPut(0xffff,URL_COMPONENTS,24)
   
   Loop,Parse,offset_name_length,|
   {
      RegExMatch(A_LoopField,"(?P<Offset>\d+)-(?P<Name>[a-zA-Z]+)-(?P<Size>\d+)",iCU_)
      VarSetCapacity(%iCU_Name%,iCU_Size,0)
      NumPut(&%iCU_Name%,URL_COMPONENTS,iCU_Offset)
      NumPut(iCU_Size,URL_COMPONENTS,iCU_Offset+4)
   }

   ; Split the given URL; extract scheme, user, pass, authotity (host), port, path, and query (extrainfo)
   ; http://msdn.microsoft.com/en-us/library/aa384376(VS.85).aspx
   DllCall("WinINet\InternetCrackUrlA","Str",lpszUrl,"uInt",StrLen(lpszUrl),"uInt",0,"uInt",&URL_COMPONENTS)

   ; Update variables to retrieve results
   Loop,Parse,offset_name_length,|
   {
      RegExMatch(A_LoopField,"-(?P<Name>[a-zA-Z]+)-",iCU_)
      VarSetCapacity(%iCU_Name%,-1)

      %arrayName%_%iCU_Name% := % %iCU_Name%
   }
   %arrayName%_nPort:=NumGet(URL_COMPONENTS,24,"uInt")
   DllCall("FreeLibrary", "UInt", hModule)                    ; unload the library
}


Its being used as this:
WinINe_InternetCrackURL(URL [,AHKarrayPrefix])
URL - the url to be cracked this is mandatory
AHKarrayPrefix - a string to indicate which AHKArray-Prefix to use for Output
When no PrefixString is given the function defaults the PrefixString to URL. Following exampleOutputs illustrates how the results 'd look like:

Here are three examples to illustrate the results
assumed URL
http://www.autohotkey.com/forum/viewtopic.php?p=206876#206876

URL_lpszScheme -> http
URL_lpszHostName -> www.autohotkey.com
URL_lpszUserName ->
URL_lpszPassword ->
URL_lpszUrlPath -> /forum/viewtopic.php
URL_lpszExtraInfo -> ?p=206876#206876
URL_nPort -> 80

assumed URL
https://www.somesecuresite.com/

URL_lpszScheme -> https
URL_lpszHostName -> www.somesecuresite.com
URL_lpszUserName ->
URL_lpszPassword ->
URL_lpszUrlPath ->
URL_lpszExtraInfo ->
URL_nPort -> 443

assumed URL
https://myusername:secret@www.somesecuresite.com:12345/path/to/file.ext?query#fragment

URL_lpszScheme -> https
URL_lpszHostName -> www.somesecuresite.com
URL_lpszUserName -> myusername
URL_lpszPassword -> secret
URL_lpszUrlPath -> /path/to/file.ext
URL_lpszExtraInfo -> ?query#fragment
URL_nPort -> 12345


below is a lil working example showing its possible usage ... in this case its getting a PathInformation to extract an ObjectName in a quoted URL style URL.

Code:

url := "http://tbn0.google.com/images?q=tbn:-RkbDeCx-wL4pM:http://www.hi-consult-"
     . "online.de/blah/HI%2520logo%25202.JPG"
WinINet_InternetCrackURL(url)
; Dump for further control
MsgBox,0,%url%,% "URL_lpszScheme:`t`t"    URL_lpszScheme    "`n"
       . "URL_lpszHostName:`t"    URL_lpszHostName  "`n"
       . "URL_lpszUserName:`t"    URL_lpszUserName  "`n"
       . "URL_lpszPassword:`t`t"  URL_lpszPassword  "`n"
       . "URL_lpszUrlPath:`t`t"   URL_lpszUrlPath   "`n"
       . "URL_lpszExtraInfo:`t`t" URL_lpszExtraInfo "`n"
       . "URL_nPort:`t`t"         URL_nPort         "`n"
RegExMatch(URL_lpszExtraInfo,"(?P<URL>http.*)",new)
WinINet_InternetCrackURL(newURL)
; Dump for further control
MsgBox,0,%newURL%,% "URL_lpszScheme:`t`t"    URL_lpszScheme    "`n"
       . "URL_lpszHostName:`t"    URL_lpszHostName  "`n"
       . "URL_lpszUserName:`t"    URL_lpszUserName  "`n"
       . "URL_lpszPassword:`t`t"  URL_lpszPassword  "`n"
       . "URL_lpszUrlPath:`t`t"   URL_lpszUrlPath   "`n"
       . "URL_lpszExtraInfo:`t`t" URL_lpszExtraInfo "`n"
       . "URL_nPort:`t`t"         URL_nPort         "`n"
; ATM we have the the Path to our picture above in the variable URL_lpszUrlPath.
; Now we just make exchange all slashes with backslashes, add some drive infotmation
; and let autohotkey handle the rest to get the pure filname
StringReplace,tmpName,URL_lpszUrlPath,/,\,All
tmpName := "C:" tmpName
SplitPath,tmpName,FileName
; the variable FileName now holds the name without any pathinformations
; all we have to do is to uriDecode it and store the decoded result
unescape:
   fileName:=uriDecode(FileName)
   if (RegExMatch(fileName,"%[0-9a-zA-Z][0-9a-zA-Z]"))
      goto unescape
MsgBox % FileName
return

uriDecode(str)
{ ; v 0.2 / (w) 25.07.2008 by derRaphael / zLib-Style release
   Loop,Parse,str,`%
   {
      if (A_Index>1)
         RegExMatch(A_LoopField,"(?P<Hex>..)(?P<rest>.*)",var)
      else
         txt := A_LoopField
      txt .= chr("0x" varHex) varRest
   }
   return txt
}


greets
DerRaphael
_________________
Back to top
View user's profile Send private message
tank



Joined: 21 Dec 2007
Posts: 1033

PostPosted: Tue Sep 09, 2008 9:01 pm    Post subject: Reply with quote

ok so question
this is still a bit deep for me (understanding this well enuff to modify it)
I can use the heck out of it tho except below
but our workplace has a proxy server and i need to use NTLM
http://msdn.microsoft.com/en-us/library/aa383144(VS.85).aspx
im a bit lost when it comes to implementing this into the scripts so far
Sad and well i dont seem to have the depth of knowledge to make anything even remotely workable from it

[ Moderator!: MSDN link fixed ]
thanks for the fix
Actually the more in the msdn i read i think i might even be pointed in the wrong direction
basically our proxy uses our Domain login information for the proxy user
In IE we arent prompted but when i use any winhttp function i get blank results
seems like im getting blocked at the proxy for instance
Code:

WININET_Init()
MsgBox % UrlGetContents("http://www.autohotkey.net")
WININET_UnInit()
return
fine at home work pc returns blank
and im able to view this site without restriction on work pc in IE
_________________
Read this
Com
Automate IE7 with Tabs
Back to top
View user's profile Send private message
ZeLen1y



Joined: 11 Oct 2006
Posts: 7

PostPosted: Mon Oct 20, 2008 12:42 pm    Post subject: Reply with quote

Whether probably to receive last-modification date of html page?
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group