[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖
本帖最后由 aa77dd@163.com 于 2016-11-29 17:18 编辑

回复 15# 523066680

有个贴吧

http://tieba.baidu.com/p/1618906999

这应该是个编码转换的 bug, 而非字节丢失

uni     GB
5A34 E6B5 娴
75AF B7E8 疯
9187 B4BC 醇

TOP

本帖最后由 523066680 于 2016-11-29 21:47 编辑

回复 16# aa77dd@163.com

是我描述上出了偏差 :]

有一首关于编码的诗
手持两把锟斤拷,口中疾呼烫烫烫。
脚踏千朵屯屯屯,笑看万物锘锘锘。

TOP

看来对于 VBS 是无解了。谢谢各位帮忙。

TOP

本帖最后由 523066680 于 2016-11-29 23:37 编辑

回复 18# tmplinshi


也许有可能,但是太折腾的话还是另辟蹊径的好。

TOP

本帖最后由 tmplinshi 于 2017-1-3 23:30 编辑

HttpQueryInfo function 文章中有这么一段话:
Note The HttpQueryInfoA function represents headers as ISO-8859-1 characters not ANSI characters. The HttpQueryInfoW function represents headers as ISO-8859-1 characters converted to UTF-16LE characters. As a result, it is never safe to use the HttpQueryInfoW function when the headers can contain non-ASCII characters. Instead, an application can use the MultiByteToWideChar and WideCharToMultiByte functions with a Codepage parameter set to 28591 to map between ANSI characters and UTF-16LE characters.


估计 "WinHttp.WinHttpRequest.5.1" 对象用的就是 HttpQueryInfoW 函数吧。
如果使用 HttpQueryInfoA 则可以正确转换编码。AHK 代码示例:

  1. MsgBox, % GetAllResponseHeaders("https://www.nyaa.se/?page=download&tid=613616")
  2. GetAllResponseHeaders(Url, RequestHeaders := "", NO_AUTO_REDIRECT := false, NO_COOKIES := false) {
  3. static INTERNET_OPEN_TYPE_DIRECT := 1
  4.      , INTERNET_SERVICE_HTTP := 3
  5.      , HTTP_QUERY_RAW_HEADERS_CRLF := 22
  6.      , CP_UTF8 := 65001
  7.      , Default_UserAgent := "Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko"
  8. hModule := DllCall("LoadLibrary", "str", "wininet.dll", "ptr")
  9. if !hInternet := DllCall("wininet\InternetOpen", "ptr", &Default_UserAgent, "uint", INTERNET_OPEN_TYPE_DIRECT
  10. , "str", "", "str", "", "uint", 0)
  11. return
  12. ; -----------------------------------------------------------------------------------
  13. if !InStr(Url, "://")
  14. Url := "http://" Trim(Url)
  15. regex := "(?P<protocol>\w+)://((?P<user>\w+):(?P<pwd>\w+)@)?(?P<host>[\w.]+)(:(?P<port>\d+))?(?P<path>.*)"
  16. RegExMatch(Url, regex, v_)
  17. if (v_protocol = "ftp") {
  18. throw, "ftp is not supported."
  19. }
  20. if (v_port = "") {
  21. v_port := (v_protocol = "https") ? 443 : 80
  22. }
  23. ; -----------------------------------------------------------------------------------
  24. Internet_Flags := 0
  25.                 | 0x400000   ; INTERNET_FLAG_KEEP_CONNECTION
  26.                 | 0x80000000 ; INTERNET_FLAG_RELOAD
  27.                 | 0x20000000 ; INTERNET_FLAG_NO_CACHE_WRITE
  28. if (v_protocol = "https") {
  29. Internet_Flags |= 0x1000  ; INTERNET_FLAG_IGNORE_CERT_CN_INVALID
  30.                | 0x2000   ; INTERNET_FLAG_IGNORE_CERT_DATE_INVALID
  31.                | 0x800000 ; INTERNET_FLAG_SECURE ; Technically, this is redundant for https
  32. }
  33. if NO_AUTO_REDIRECT
  34. Internet_Flags |= 0x00200000 ; INTERNET_FLAG_NO_AUTO_REDIRECT
  35. if NO_COOKIES
  36. Internet_Flags |= 0x00080000 ; INTERNET_FLAG_NO_COOKIES
  37. ; -----------------------------------------------------------------------------------
  38. hConnect := DllCall("wininet\InternetConnect", "ptr", hInternet, "ptr", &v_host, "uint", v_port
  39. , "ptr", &v_user, "ptr", &v_pwd, "uint", INTERNET_SERVICE_HTTP, "uint", Internet_Flags, "uint", 0, "ptr")
  40. hRequest := DllCall("wininet\HttpOpenRequest", "ptr", hConnect, "str", "HEAD", "ptr", &v_path
  41. , "str", "HTTP/1.1", "ptr", 0, "ptr", 0, "uint", Internet_Flags, "ptr", 0, "ptr")
  42. nRet := DllCall("wininet\HttpSendRequest", "ptr", hRequest, "ptr", &RequestHeaders, "int", -1
  43. , "ptr", 0, "uint", 0)
  44. Loop, 2 {
  45. DllCall("wininet\HttpQueryInfoA", "ptr", hRequest, "uint", HTTP_QUERY_RAW_HEADERS_CRLF
  46. , "ptr", &pBuffer, "uint*", bufferLen, "uint", 0)
  47. if (A_Index = 1)
  48. VarSetCapacity(pBuffer, bufferLen, 0)
  49. }
  50. ; -----------------------------------------------------------------------------------
  51. output := StrGet(&pBuffer, "UTF-8")
  52. ; -----------------------------------------------------------------------------------
  53. DllCall("wininet\InternetCloseHandle", "ptr", hRequest)
  54. DllCall("wininet\InternetCloseHandle", "ptr", hConnect)
  55. DllCall("wininet\InternetCloseHandle", "ptr", hInternet)
  56. DllCall("FreeLibrary", "Ptr", hModule)
  57. return output
  58. }
复制代码

TOP

返回列表