我需要使用vbscript连接到need服务器。使用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
发布于 2017-06-01 02:19:51
它可以在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。例如:
xmlHttp.Option(0) = "http_requester/0.1"
xmlHttp.Option(4) = 13056
xmlHttp.Option(6) = "True"
xmlhttp.Option(12) = "True"https://stackoverflow.com/questions/44287633
复制相似问题