0

我对 VBA 中的 MSXML2.XMLHTTP 对象有疑问。我需要在 json 中发送一条消息,但 auth 令牌中有双引号。因此,为了让这些双引号到达消息中,使用了反斜杠。现在通过将 xml 解析为 Json,xmlhttp 对象添加了一个额外的反斜杠。

基本上我发送这个“Token token=\x22AAA\x22”

并且服务器接收到这个“Token token=\\x22AAA\\x22”

Sub cmdOAuth2_Click()

  Dim webServiceURL As String
  Dim actionType As String
  Dim targetWord As String
  Dim actionType2 As String
  Dim targetWord2 As String

  webServiceURL = "https://api.esios.ree.es/archives"

  actionType = "Accept"
  targetWord = "application/json"
  actionType2 = "Content-Type"
  targetWord2 = "application/json"
  actionType3 = "Host"
  targetWord3 = "api.esios.ree.es"
  actionType4 = "Authorization"
  targetWord4 = "Token token=\x22AAA\x22"
  actionType5 = "Cookie"
  targetWord5 = " "

  With CreateObject("MSXML2.XMLHTTP")
    .Open "GET", webServiceURL, False
    .setRequestHeader actionType, targetWord
    .setRequestHeader actionType2, targetWord2
    .setRequestHeader actionType3, targetWord3
    .setRequestHeader actionType4, targetWord4
    .setRequestHeader actionType5, targetWord5
    .send 
    If .Status = 200 Then
      Debug.Print .responseText
      MsgBox .getAllResponseHeaders
    Else
      Debug.Print .Status & ": " & .statusText
    End If
  End With

End Sub
4

0 回答 0