我有4个不同的IPR 1.2.3.4(ip-reputation)查询到IBM的Xforce数据库,使用基本身份验证(base64编码)以及URL信誉。我在python中的版本效果很好,打印出适当的JSON信息:
...
if __name__ == '__main__':
apiKey = "1234...."
apiPwd = "5678..."
result = requests.get('https://xforce-api.mybluemix.net:443/ipr/1.2.3.4', verify=False,auth=(apiKey, apiPwd))
if result.status_code != 200:
print( "~ Bad Status Code: {}".format(result.status_code))
else:
print("~ The result is {}".format(result.status_code))
print("~ Rx Data={}".format(result._content))
Go中的版本(使用来自github的demisto&goxforce)效果很好。设置环境变量键和密码后,我发出命令行: ' xforceQuery -cmd ipr -q 1.2.3.4'
并且再次完美地打印出关于1.2.3.4的json信息。
我使用名为' Postman'的浏览器实用程序,使用我的用户/密钥和密码指定基本身份验证,Accept:application / json,Accept-Language:en和Content-的标题输入:application / json,再次,它给了我正确的信息(参见下面的.gif文件)
另一方面,我在VBA中尝试相同的操作,我得到了“错误:未经授权”#39;这段代码有什么问题?
Public Sub testXF()
Dim myKey As String
Dim myPass As String
myKey = "1234..."
myPass = "5678..."
pHtml = "xforce"
Dim ohttp As MSXML2.ServerXMLHTTP60
Set ohttp = New MSXML2.ServerXMLHTTP60
If timeout = 0 Then timeout = 60
ohttp.Open "GET", "https://xforce-api.mybluemix.net:443/ipr/1.2.3.4", False, myKey, myPass
With ohttp
.SetRequestHeader "Content-Type", "application/json"
.SetRequestHeader "Accept", "application/json"
.SetRequestHeader "Accept-Language", "en"
.SetTimeouts 0, 30 * 1000, 30 * 1000, timeout * 1000
.SetRequestHeader "Authorization", "Basic " + _
Base64Encode(myKey + ":" + myPass)
.SetRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"
End With
ohttp.Send ("")
With ohttp
pStatus = .status
pText = .ResponseText
pResponseHeaders = .GetAllResponseHeaders()
End With
Debug.Print "GET", pStatus, pText
Set ohttp = Nothing
End Sub