用途说明
curl命令是一个功能强大的网络工具,它能够通过http、ftp等方式下载文件,也能够上传文件。其实curl远不止前面所说的那些功能,大家可以通过man curl阅读手册页获取更多的信息。类似的工具还有wget。
curl命令使用了libcurl库来实现,libcurl库常用在C程序中用来处理HTTP请求,curlpp是libcurl的一个C++封装,这几个东西可以用在抓取网页、网络监控等方面的开发,而curl命令可以帮助来解决开发过程中遇到的问题。
LibCurl_Examples_A_Global.ahk 代码片段
#NoEnv #Warn All #Warn LocalSameAsGlobal, Off #Include LibCurl.ahk ; First function to call is Curl.Initialize. ; Point it to the folder with all necessary dll-files. Curl.Initialize("Libs") ; Example 1: GetVersion ; ====================== ; Returns version string MsgBox % "Example 1: GetVersion`n" . "`n" . Curl.GetVersion() ; Example 2: GetVersionInfo ; ========================== ; Returns object with all possible information about this particular build of libcurl versionInfo := Curl.GetVersionInfo() versionMsg := "" For key, value In versionInfo { versionMsg .= key ":`t" value "`n" } MsgBox % "Example 2: GetVersionInfo`n" . "`n" . versionMsg ; Example 3: GetDate ; =================== ; Converts date-string to unix-time integer ; Almost all date-string formats used in HTTP are supported. ; YMDH24MISS is also supported. Default value is A_NowUTC. MsgBox % "Example 3: GetDate`n" . "`n" . Curl.GetDate() . "`n" . Curl.GetDate(19940825012257) . "`n" . Curl.GetDate("Sun, 06 Nov 1994 08:49:37 GMT") . "`n" . Curl.GetDate("Sat, 11 Sep 2004 21:32:11 +0200") . "`n" . Curl.GetDate("20040912 15:05:58 -0700") ; Example 4: EscapeStr / UnescapeStr ; =================================== ; Url-encodes given string. ; You can set encoding as a second argument. ; By default string is converted to UTF-8 prior to encoding. ; Alternatively, you can get pointer to resulting string. MsgBox % "Example 4.1: EscapeStr" . "`n" . "`n String:" . "`n" . Curl.EscapeStr("Привет мир") . "`n" . "`n String with encoding:" . "`n" . Curl.EscapeStr("Γεια Σας Κόσμο", "CP1253") . "`n" . "`n Pointer:" . "`n" . (strPtr := Curl.EscapeStr("你好世界", "", True)) . "`n" . "`n String from pointer:" . "`n" . StrGet(strPtr, "CP0") ; If you get pointers, free them yourself Curl._Free(strPtr) ; Url-decodes given string ; You can set encoding as a second argument. ; By default string is converted from UTF-8 after decoding. ; Alternatively, you can get pointer to resulting string. ; If you pass variable as third argument, it will be set to length of resulting string. MsgBox % "Example 4.2: UnescapeStr" . "`n" . "`n String:" . "`n" . Curl.UnescapeStr("%E3%83%8F%E3%83%AD%E3%83%BC%E3%83%BB%E3%83%AF%E3%83%BC%E3%83%AB%E3%83%89") . "`n" . "`n String with encoding:" . "`n" . Curl.UnescapeStr("Merhaba%20D%FCnya", "CP1254") . "`n" . "`n Pointer and length:" . "`n" . (strPtr := Curl.UnescapeStr("Hej%20v%C3%A4rlden", "", varLen := 0)) . "`n" . "`n String from pointer:" . "`n" . StrGet(strPtr, varLen, "UTF-8") . " (" . varLen . " chars)" Curl._Free(strPtr) ; Example 5: SniffMimeType ; ======================== ; Not a libcurl function, but it's quite handy. ; Tries to detect mime-type from url-string or data buffer. testData := "" VarSetCapacity(testData, 256, 0) testFile := FileOpen("C:\Windows\Web\Wallpaper\Nature\img1.jpg", "r") testFile.RawRead(&testData, 256) testFile.Close() MsgBox % "Example 5: SniffMimeType`n" . "`n" . Curl.SniffMimeType("http://example.com/test.png") . "`n" . Curl.SniffMimeType("http://example.com/test.jpg") . "`n" . Curl.SniffMimeType("http://example.com/test.dll") . "`n" . Curl.SniffMimeType("", &testData, 16)
打包下载地址:
声明:站内资源为整理优化好的代码上传分享与学习研究,如果是开源代码基本都会标明出处,方便大家扩展学习路径。请不要恶意搬运,破坏站长辛苦整理维护的劳动成果。本站为爱好者分享站点,所有内容不作为商业行为。如若本站上传内容侵犯了原著者的合法权益,请联系我们进行删除下架。
评论(0)