Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there really no way to prevent Invoke-WebRequest from following redirections

Tags:

powershell

It seems the Invoke-WebRequest cmdlet provides no way to inspect redirecting responses (by saying "don't follow redirections"). This would make the curl-alias not only ridiculous but even more than superfluous.

Can anybody spare me this disappointment?

like image 464
TNT Avatar asked Aug 17 '16 11:08

TNT


People also ask

How do I use invoke WebRequest without Internet Explorer?

By default, Invoke-WebRequest tries to use Internet Explorer (IE) to parse the HTML returned. This doesn’t work on systems without IE. To get around that, we can use the UseBasicParsing parameter to still download the content but only lightly parse it.

What does the invoke-WebRequest cmdlet do?

The Invoke-WebRequest cmdlet sends HTTP and HTTPS requests to a web page or web service. It parses the response and returns collections of links, images, and other significant HTML elements. This cmdlet was introduced in

What is the body of a WebRequest?

The body is the content of the request that follows the headers. You can also pipe a body value to Invoke-WebRequest. The Body parameter can be used to specify a list of query parameters or specify the content of the response.

Does invoke-WebRequest support proxy configuration defined by environment variables?

Beginning in PowerShell 7.0, Invoke-WebRequest supports proxy configuration defined by environment variables. See the Notes section of this article. Examples Example 1: Send a web request. This example uses the Invoke-WebRequest cmdlet to send a web request to the Bing.com site.


1 Answers

Use the MaximumRedirection parameter to prevent implicit redirects from occuring:

Invoke-WebRequest http://www.google.com -MaximumRedirection 0
like image 190
Mathias R. Jessen Avatar answered Sep 21 '22 14:09

Mathias R. Jessen