Asp 將MSXML2.serverXMLHTTP返回的responseBody 內容轉換成支持中文編碼


參考: ASP四個小技巧,抓取網頁:GetBody,字節轉字符BytesToBstr,正則表達式測試方法,生成靜態頁
   
   
   
           
  1. Function GetBody(weburl)
  2. '創建對象
  3. Dim ObjXMLHTTP
  4. Set ObjXMLHTTP=Server.CreateObject("MSXML2.serverXMLHTTP")
  5. '請求文件,以異步形式
  6. ObjXMLHTTP.Open "GET",weburl,False
  7. '此信息必須在send前一個設置否則將出錯"msxml3.dll error '80004005' Unspecified error"
    xmlhttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
    '如果下面的方法在調用時使用()則會出現以下錯誤,如果非要使用()則需要使用call來調用方法
    “ Microsoft VBScript compilation error '800a0414'Cannotuse parentheses when calling a Sub”
    'xmlhttp.setRequestHeader ("Content-Type", "application/x-www-form-urlencoded")

  8. ObjXMLHTTP.send
  9. While ObjXMLHTTP.readyState <> 4
  10. ObjXMLHTTP.waitForResponse 1000
  11. Wend
  12. '得到結果
  13. GetBody=ObjXMLHTTP.responseBody
  14. '釋放對象
  15. Set ObjXMLHTTP=Nothing
  16. End Function
  17. Function BytesToBstr(body,Cset)
  18. dim objstream
  19. set objstream = Server.CreateObject("adodb.stream")
  20. objstream.Type = 1
  21. objstream.Mode =3
  22. objstream.Open
  23. objstream.Write body
  24. objstream.Position = 0
  25. objstream.Type = 2
  26. objstream.Charset = Cset
  27. BytesToBstr = objstream.ReadText
  28. objstream.Close
  29. set objstream = nothing
  30. End Function






免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM