Joe*_*oey 63 powershell web-services
A web service I need to interact with (often manually for testing) requires an extra HTTP header on certain requests. Quick manual testing works quite great with PowerShell's New-WebServiceProxy but so far I haven't found an option to add another HTTP header to the request.
Is there something for that?
Mad*_*kor 107
Invoke-WebRequest http://yourURLhere -Headers @{"accept"="application/json"}
Run Code Online (Sandbox Code Playgroud)
Wha*_*ool 21
您可以使用PowerShell的.NET Web客户端.
> $webClient = New-Object System.Net.WebClient
> $webClient.Headers.add('accept','application/json')
> $webClient.DownloadString('http://yourURLhere')
Run Code Online (Sandbox Code Playgroud)
我很惊讶这没有出现:
$uri = 'http://...'
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add('Accept','Application/Json')
$headers.Add('X-My-Header','...')
$result = Invoke-WebRequest -Uri $uri -Headers $headers
Run Code Online (Sandbox Code Playgroud)
为完整起见,对headers属性的引用:
https://msdn.microsoft.com/en-us/library/s4ys34ea(v=vs.110).aspx
| 归档时间: |
|
| 查看次数: |
75328 次 |
| 最近记录: |