[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖
  1. Const adTypeBinary = 1
  2. Const adTypeText = 2
  3. ' accept a string and convert it to Bytes array in the selected Charset
  4. Function StringToBytes(Str,Charset)
  5.   ' Dim Stream
  6.   Set Stream = CreateObject("ADODB.Stream")
  7.   Stream.Type = adTypeText
  8.   Stream.Charset = Charset
  9.   Stream.Open
  10.   Stream.WriteText Str
  11.   Stream.Flush
  12.   Stream.Position = 0
  13.   ' rewind stream and read Bytes
  14.   Stream.Type = adTypeBinary
  15.   StringToBytes= Stream.Read
  16.   Stream.Close
  17.   Set Stream = Nothing
  18. End Function
  19. ' accept Bytes array and convert it to a string using the selected charset
  20. Function BytesToString(Bytes, Charset)
  21.   ' Dim Stream
  22.   Set Stream = CreateObject("ADODB.Stream")
  23.   Stream.Charset = Charset
  24.   Stream.Type = adTypeBinary
  25.   Stream.Open
  26.   Stream.Write Bytes
  27.   Stream.Flush
  28.   Stream.Position = 0
  29.   ' rewind stream and read text
  30.   Stream.Type = adTypeText
  31.   BytesToString= Stream.ReadText
  32.   Stream.Close
  33.   Set Stream = Nothing
  34. End Function
  35. ' This will alter charset of a string from 1-byte charset(as windows-1252)
  36. ' to another 1-byte charset(as windows-1251)
  37. Function AlterCharset(Str, FromCharset, ToCharset)
  38.   Dim Bytes
  39.   Bytes = StringToBytes(Str, FromCharset)
  40. ' HEXS=""
  41. ' for i = 1 to LenB(Bytes)
  42. ' HEXS = HEXS & hex(ascb(MidB (Bytes, i, 1))) & ","
  43. ' next
  44. ' MsgBox HEXS
  45.   AlterCharset = BytesToString(Bytes, ToCharset)
  46. End Function
  47. Set objWinHttp = CreateObject("WinHttp.WinHttpRequest.5.1")
  48. objWinHttp.Open "HEAD", "https://www.nyaa.se/?page=download&tid=613616"
  49. objWinHttp.Send
  50. MsgBox objWinHttp.GetResponseHeader("Content-Disposition")
  51. ' MsgBox LenB ( objWinHttp.GetResponseHeader("Content-Disposition") )
  52. MsgBox AlterCharset( objWinHttp.GetResponseHeader("Content-Disposition"), "GB2312", "utf-8")
复制代码

TOP

本帖最后由 aa77dd@163.com 于 2016-11-29 16:50 编辑

数据如此: 这是什么编码我完全不知道
  1. 69,0,6E,0,6C,0,69,0,6E,0,65,0,3B,0,20,0,66,0,69,0,6C,0,65,0,6E,0,61,0,6D,0,65,0,3D,0,22,0,34,5A,AF,75,87,91,1C,94,3F,0,36,0,35,0,2E,0,72,0,61,0,72,0,2E,0,74,0,6F,0,72,0,72,0,65,0,6E,0,74,0,22,0,
复制代码
其中 34,5A,AF,75,87,91,1C,94,3F  按 UTF-16 LE 解码为 娴疯醇鐜

另外 ahk 也可以用
ComObjCreate("Msxml2.XMLHTTP")

之类

我觉得是 WinHttp 或者 VBS 的问题
  1. Const adTypeBinary = 1
  2. Const adTypeText = 2
  3. ' accept a string and convert it to Bytes array in the selected Charset
  4. Function StringToBytes(Str,Charset)
  5.   ' Dim Stream
  6.   Set Stream = CreateObject("ADODB.Stream")
  7.   Stream.Type = adTypeText
  8.   Stream.Charset = Charset
  9.   Stream.Open
  10.   Stream.WriteText Str
  11.   Stream.Flush
  12.   Stream.Position = 0
  13.   ' rewind stream and read Bytes
  14.   Stream.Type = adTypeBinary
  15.   StringToBytes= Stream.Read
  16.   Stream.Close
  17.   Set Stream = Nothing
  18. End Function
  19. ' accept Bytes array and convert it to a string using the selected charset
  20. Function BytesToString(Bytes, Charset)
  21.   ' Dim Stream
  22.   Set Stream = CreateObject("ADODB.Stream")
  23.   Stream.Charset = Charset
  24.   Stream.Type = adTypeBinary
  25.   Stream.Open
  26.   Stream.Write Bytes
  27.   Stream.Flush
  28.   Stream.Position = 0
  29.   ' rewind stream and read text
  30.   Stream.Type = adTypeText
  31.   BytesToString= Stream.ReadText
  32.   Stream.Close
  33.   Set Stream = Nothing
  34. End Function
  35. ' This will alter charset of a string from 1-byte charset(as windows-1252)
  36. ' to another 1-byte charset(as windows-1251)
  37. Function AlterCharset(Str, FromCharset, ToCharset)
  38.   Dim Bytes
  39.   Bytes = StringToBytes(Str, FromCharset)
  40.   
  41.   AlterCharset = BytesToString(Bytes, ToCharset)
  42. End Function
  43. Set objWinHttp = CreateObject("WinHttp.WinHttpRequest.5.1")
  44. objWinHttp.Open "HEAD", "https://www.nyaa.se/?page=download&tid=613616"
  45. objWinHttp.Send
  46. MsgBox objWinHttp.GetResponseHeader("Content-Disposition")
  47. MsgBox LenB ( objWinHttp.GetResponseHeader("Content-Disposition") )
  48.         HEXS=""
  49.         for i = 1 to LenB(objWinHttp.GetResponseHeader("Content-Disposition"))
  50.                 HEXS = HEXS & hex(ascb(MidB (objWinHttp.GetResponseHeader("Content-Disposition"), i, 1))) & ","
  51.         next
  52.         MsgBox HEXS
  53. MsgBox AlterCharset( objWinHttp.GetResponseHeader("Content-Disposition"), "GB2312", "utf-8")
复制代码

TOP

回复 13# 523066680

问题可能出现在 GetResponseHeader("Content-Disposition") 方法
  1. req := ComObjCreate("Microsoft.XMLHTTP")
  2. ; Open a request with async enabled.
  3. req.open("GET", "https://www.nyaa.se/?page=download&tid=613616", true)
  4. ; Set our callback function (v1.1.17+).
  5. req.onreadystatechange := Func("Ready")
  6. ; Send the request.  Ready() will be called when it's complete.
  7. req.send()
  8. ; /*
  9. ; If you're going to wait, there's no need for onreadystatechange.
  10. ; Setting async=true and waiting like this allows the script to remain
  11. ; responsive while the download is taking place, whereas async=false
  12. ; will make the script unresponsive.
  13. while req.readyState != 4
  14.     sleep 100
  15. ; */
  16. #Persistent
  17. Ready() {
  18.     global req
  19.     if (req.readyState != 4)  ; Not done yet.
  20.         return
  21.     if (req.status == 200 || req.status == 304) {
  22.         MsgBox % "responseText: " req.responseText
  23. t:=req.GetResponseHeader("Content-Disposition")
  24.         MsgBox % "Content-Disposition: " t
  25. }
  26.     else
  27.         MsgBox 16,, % "Status " req.status
  28.     ExitApp
  29. }
复制代码

TOP

本帖最后由 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

返回列表