XMLHTTP(IIS)上的API请求失败

时间:2018-10-11 19:10:56

标签: json vbscript asp-classic iis-8

我正在尝试使用XMLHTTP.6.0对象向API发送请求(POST)。

在Postman中运行相同的过程时,它的工作原理很像-但在通过IIS(ASP)在VB中运行它时,响应服务器似乎甚至没有收到指定的授权标头。

一直在试图弄清为什么这种情况整天没有运气。

任何人都知道为什么远程服务器不获取Authorization标头吗?

<%
Function ASPPostJSON(url)
Dim objXmlHttp

Set objXmlHttp = Server.CreateObject("Msxml2.XMLHTTP.6.0")

  objXmlHttp.Open "POST", url, false, "nouser", "nopwd"
  objXmlHttp.setRequestHeader "Accept", "*/*"
  objXmlHttp.SetRequestHeader "Authorization", "Basic VGVzdEZpbmFuczpHUTJUR05KUUdFWURNTlJURzQzR0laUldHNVFXR1pSVA=="
  objXmlHttp.SetRequestHeader "cache-control", "no-cache"
  objXmlHttp.SetRequestHeader "content-length", "26"
  objXmlHttp.SetRequestHeader "Content-Type", "application/json"

'send the json string to the API server
 objXmlHttp.Send "{""PNR"": 194803234857 }"

'If objXmlHttp.Status = 200 Then
 ASPPostJSON = CStr(objXmlHttp.ResponseText)
'end if

'return the response from the API server
 Response.write(ASPPostJSON)
 Set objXmlHttp = Nothing

End Function

'call the function and pass the API URL
 call ASPPostJSON("https://api.testserver.com/v2/person")
%>

0 个答案:

没有答案