是否有可能通过新WebServiceProxy发送额外的HTTP标头Web服务

问题描述 投票:56回答:3

Web服务,我需要进行交互(通常是手工测试)需要在某些请求额外的HTTP标头。快速手动测试工作非常伟大的PowerShell的New-WebServiceProxy但到目前为止,我还没有找到一个选择的另一种HTTP标头添加到该请求。

有什么是什么?

web-services powershell
3个回答
103
投票
Invoke-WebRequest http://yourURLhere -Headers @{"accept"="application/json"}

介绍了在POSH 3.0


20
投票

你可以使用.NET的Web客户端从PowerShell中。

> $webClient = New-Object System.Net.WebClient
> $webClient.Headers.add('accept','application/json')
> $webClient.DownloadString('http://yourURLhere')

9
投票

我很惊讶这还没有上来:

$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

为了完整起见,在标题属性的引用:

https://msdn.microsoft.com/en-us/library/s4ys34ea(v=vs.110).aspx

© www.soinside.com 2019 - 2024. All rights reserved.