2017-05-31 43 views
0

我需要使用vbscript連接到網絡服務器。使用PowerShell這個作品完美無瑕:http-basic-auth針對web服務器與vbs

$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

它可以在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"