authentication - Why won't this VBA program using ServerXMLHTTP60 authenticate properly? -
i have 4 different queries of ipr 1.2.3.4 (ip-reputation) ibm's xforce database, using basic authentication (base64 encoded), url-reputation. version in python works great, printing out appropriate json information:
... 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("~ result {}".format(result.status_code)) print("~ rx data={}".format(result._content))
the version in go (using demisto's goxforce github) works great. after setting environment-variable key , password, issue commandline: 'xforcequery -cmd ipr -q 1.2.3.4'
and prints out json information 1.2.3.4, again, perfectly.
i use browser-utility called 'postman', specify basic authentication user/key , password, headers of accept: application/json, accept-language: en, , content-type: application/json, and, again, gives me proper information (see .gif, below)
on other hand, try same thing in vba, , '401 error: not authorized'. what's wrong code?
public sub testxf() dim mykey string dim mypass string mykey = "1234..." mypass = "5678..." phtml = "xforce" dim ohttp msxml2.serverxmlhttp60 set ohttp = new msxml2.serverxmlhttp60 if timeout = 0 timeout = 60 ohttp.open "get", "https://xforce-api.mybluemix.net:443/ipr/1.2.3.4", false, mykey, mypass 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 ohttp.send ("") ohttp pstatus = .status ptext = .responsetext presponseheaders = .getallresponseheaders() end debug.print "get", pstatus, ptext set ohttp = nothing end sub
Comments
Post a Comment