我需要使用vbscript连接到网络服务器。使用powershell,这可以完美无缺:
$url = "https://someserver:9200/?q=name:Hans"
$headers = @{ Authorization = "Basic c29tZXVzZXI6c29tZXBhc3M=" }
$result = Invoke-WebRequest -Uri $url -Method Post -Body $body -ContentType application/x-www-form-urlencoded -Headers $headers
现在我需要对vbscript做同样的事情:
url = "https://someserver:9200/?q=name:Hans"
Set xmlHttp = CreateObject("WinHTTP.WinHTTPRequest.5.1")
xmlHttp.Open "POST", url, false
xmlHttp.SetRequestHeader "Authorization", "Basic c29tZXVzZXI6c29tZXBhc3M="
xmlHttp.SetRequestHeader "Content-Type", "application/x-www-form-urlencoded"
xmlHttp.send
可悲的是,这给了我一个错误:
A certificate is required to complete client authentication
我做错了什么?
beMoD
答案 0 :(得分:0)
它在PowerShell中工作,因为[WebRequest]对象设置了一堆默认参数,它看起来像WinHTTPRequest COM(https://msdn.microsoft.com/en-us/library/windows/desktop/aa383998(v=vs.85).aspx)对象没有。为了手动设置这些属性,您需要使用WinHTTPRequest对象上的.Option属性来设置索引,其值与所需的WinHTTPRequest枚举相匹配:(https://msdn.microsoft.com/en-us/library/windows/desktop/aa384108(v=vs.85).aspx)。 E.g:
xmlHttp.Option(0) = "http_requester/0.1"
xmlHttp.Option(4) = 13056
xmlHttp.Option(6) = "True"
xmlhttp.Option(12) = "True"