Iczer Posted June 19, 2016 Share Posted June 19, 2016 (edited) trying to make some download tool, but have 2 issues with curl.exe: 1. If I set user custom agent header, curl do not process "' --remote-name --remote-header-name '" settings. Otherwise downloaded file get proper name (from server). 2. If I try download file, which have unicode letters in FileName, download goes OK, but file on disk would have broken unicode letters in FileName () expandcollapse popup#include <WinAPI.au3> $sDownloadUrl = "https://www.autoitscript.com/forum/applications/core/interface/file/attachment.php?id=51443"; eng filename ;$sDownloadUrl = "https://www.autoitscript.com/forum/applications/core/interface/file/attachment.php?id=51442"; unicode filename $sPath = @TempDir $sFileName = "" cURL_CLI_Download($sDownloadUrl, $sPath, $sFileName) Func cURL_CLI_Download($sDownloadUrl = "", $sPath = "", $sFileName = "") $sDownloadUrl = _WinAPI_WideCharToMultiByte($sDownloadUrl, 65001, True ) $sFileName = _WinAPI_WideCharToMultiByte($sFileName, 65001, True ) Local $aURI = StringRegExp($sDownloadUrl,'^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?',3), $code = "" $code &= ' --header "User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Firefox/45.0" ' $code &= ' --header "Referer: ' & $aURI[0] & $aURI[2] & '" ' $code &= ' --header "Accept-Charset: utf-8" ' If $sFileName == "" Then $code &= ' --remote-name --remote-header-name ' Else $code &= ' --output "' & $sFileName & '" ' EndIf $code &= '--location ' $code &= '--connect-timeout "88" ' $code &= '"'&$sDownloadUrl&'" ' ;$code = 'curl --help' If Not ($sPath == "") Then If Not FileExists($sPath) Then DirCreate($sPath) ;FileChangeDir($sPath) EndIf ConsoleWrite($code & @CRLF) ConsoleWrite(@ScriptDir & "\curl.exe" & @CRLF) $iPID = Run(@ScriptDir & "\curl.exe --trace-ascii - " & $code, $sPath, @SW_HIDE,$STDERR_MERGED) ProcessWaitClose($iPID) $sOutput = StdoutRead($iPID) StdioClose($iPID) ConsoleWrite("$sOutput = "&$sOutput & @CRLF) EndFunc Is there a something wrong with my approach to curl.exe? いくつかのファイル名.txt Some File Name.txt Edited June 19, 2016 by Iczer Link to comment Share on other sites More sharing options...
jchd Posted June 19, 2016 Share Posted June 19, 2016 You can't pass UTF8 strings to console programs unless the default charset for console is 65001. This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
Iczer Posted June 19, 2016 Author Share Posted June 19, 2016 is there a fast way to change default charset for console back and forth? if not, punicode is only way? Link to comment Share on other sites More sharing options...
jchd Posted June 20, 2016 Share Posted June 20, 2016 Look here : This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
Iczer Posted June 21, 2016 Author Share Posted June 21, 2016 thanks! interesting, if i set user-agent like: $code &= ' --user-agent "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:40.0) Gecko/20100101 Firefox/"' $code &= ' --user-agent "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:40.0) Gecko/20100101 Firefox/dlfjldfkjdf"' $code &= ' --user-agent "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:40.0) Gecko/20100101 Firefox/ 40.0"' downloaded file is written to disk, but $code &= ' --user-agent "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:40.0) Gecko/20100101 Firefox/*any digit*"' then file is not created is there a some way to escape characters (digits or slashes) in curl so firefox user agent can be used? Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now