Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to send additional HTTP headers to web services via New-WebServiceProxy

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?

like image 642
Joey Avatar asked Oct 17 '12 14:10

Joey


People also ask

How many headers can an HTTP request have?

HTTP does not place a predefined limit on the length of each header field or on the length of the header section as a whole, as described in Section 2.5.

How do I add HTTP headers?

Select the web site where you want to add the custom HTTP response header. In the web site pane, double-click HTTP Response Headers in the IIS section. In the actions pane, select Add. In the Name box, type the custom HTTP header name.

Can I add custom header to HTTP request?

In the Home pane, double-click HTTP Response Headers. In the HTTP Response Headers pane, click Add... in the Actions pane. In the Add Custom HTTP Response Header dialog box, set the name and value for your custom header, and then click OK.

Can HTTP headers be modified?

You can manipulate the headers of incoming HTTP requests through HTTP Request Header Modification Rules. Through these rules you can: Set the value of an HTTP request header to a literal string value, overwriting its previous value or adding a new header to the request.


2 Answers

Invoke-WebRequest http://yourURLhere -Headers @{"accept"="application/json"} 

Introduced in POSH 3.0

like image 67
Madu Alikor Avatar answered Sep 26 '22 19:09

Madu Alikor


You could use .NET's web client from PowerShell.

> $webClient = New-Object System.Net.WebClient > $webClient.Headers.add('accept','application/json') > $webClient.DownloadString('http://yourURLhere') 
like image 32
What Would Be Cool Avatar answered Sep 23 '22 19:09

What Would Be Cool