我在检索xml请求时遇到问题,我收到错误
Run-time error '-2147023783(80070459)':
No mapping for the Unicode character exists in the target multi-byte code page.
正在检索的数据中包含»字符。现在我知道它与由于位分配不同而无法正确映射这一事实有关,但是必须有一种方法可以将其去除或转换它。
我尝试过使用VBA.Strings.StrConv()但它仍然会提供相同的错误消息
Function getData(XMLString As String) As String
Dim sURL, sResult, sHeaderResult, strPostData, sXmlDocument, resultsformat, sepChar, wholeLine As String
Dim subStrCount, i, colNdx, pos, nextPos, saveColNdx, maxRows, maxCols As Integer
ReDim subStr(0) As String
Dim oHttp, myDom, MyData As Object
Dim rowNdx As Long
Dim tempVal As Variant
Dim myRange As Range
'URL to open
sURL = "http://website.com"
'Create Post Data
With Worksheets("Control")
strPostData = "action=" & .Range("Action").Value & "&baseviewid=" & .Range("BaseViewID").Value & "&key=" & .Range("Key").Value & "&resultsformat=" & .Range("Format").Value & "&userid=" & .Range("UserID").Value
End With
' Create an XMLDocument object and add some error trapping
On Error Resume Next
Set myDom = CreateObject("MSXML2.DOMDocument")
If Err.Number <> 0 Then
MsgBox "Error 0 has occured while creating a MSXML2.DOMDocument object"
End If
'Load XML text
myDom.LoadXML XMLString
' Create an XMLHTTP object and add some error trapping
On Error Resume Next
Set oHttp = CreateObject("WinHttp.WinHttpRequest.5.1")
If Err.Number <> 0 Then
Set oHttp = CreateObject("MSXML.XMLHTTPRequest")
MsgBox "Error 0 has occured while creating a MSXML.XMLHTTPRequest object"
End If
On Error GoTo 0
If oHttp Is Nothing Then
MsgBox "For some reason I wasn't able to make a MSXML2.XMLHTTP object"
Exit Function
End If
'Join all parameters in one string
strPostData = strPostData & "&xmlquery=" & myDom.XML
'SEND REQUEST WITH ALL THE PARAMETERS
With oHttp
.SetProxy 2, "http://proxy.something.com:8443"
.Open "POST", sURL, False
.SetTimeouts 120000, 120000, 120000, 120000
.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
.send (strPostData)
sHeaderResult = .GetAllResponseHeaders
sResult = responseText
'sResult = VBA.Strings.StrConv(.responseText, vbFromUnicode)
'sResult = VBA.Strings.StrConv(.responseText, vbUnicode)
End With
getData = sResult
End Function
偶尔会出现很多中文字符而不是错误。如果我使用没有任何异常字符的数据,查询将按预期工作。
任何解决方法都将不胜感激!