如何使用Invoke-WebRequest查看发送的headers?
How to use Invoke-WebRequest to see the sent headers?
当我使用以下命令时:
Invoke-WebRequest -UseBasicParsing -Uri http://example.com -SessionVariable Foo -UserAgent Bar
我得到以下输出:
StatusCode : 200
StatusDescription : OK
Content : <!doctype html>
<html>
<head>
<title>Example Domain</title>
<meta charset="utf-8" />
<meta http-equiv="Content-type" content="text/html;
charset=utf-8" />
<meta name="viewport" conten...
RawContent : HTTP/1.1 200 OK
Vary: Accept-Encoding
X-Cache: HIT
Content-Length: 1270
Cache-Control: max-age=604800
Content-Type: text/html
Date: Mon, 19 Feb 2018 16:38:28 GMT
Expires: Mon, 26 Feb 2018 16:38...
Forms :
Headers : {[Vary, Accept-Encoding], [X-Cache, HIT], [Content-Length,
1270], [Cache-Control, max-age=604800]...}
Images : {}
InputFields : {}
Links : {@{outerHTML=<a
href="http://www.iana.org/domains/example">More
information...</a>; tagName=A;
href=http://www.iana.org/domains/example}}
ParsedHtml :
RawContentLength : 1270
但问题是,我看不到发送的 headers(session 变量或用户代理)。也许它被 ...
截断了?
如何显示已发送的 headers?
Invoke-WebRequest
不存储请求 header AFAIK。如果您想要 header 中的特定值,那么它希望您使用参数 -Headers
和 -UserAgent
.
指定它们
如果您愿意,HttpWebRequest
或 WebRequest
提供更多控制。
$req = [System.Net.HttpWebRequest]::Create("http://www.whosebug.com")
$res = $req.GetResponse()
$req.Headers.Keys | % { "$_ = $($req.Headers[$_])" }
Host = whosebug.com
$req | fl Method, UserAgent, ProtocolVersion
Method : GET
UserAgent :
ProtocolVersion : 1.1
当我使用以下命令时:
Invoke-WebRequest -UseBasicParsing -Uri http://example.com -SessionVariable Foo -UserAgent Bar
我得到以下输出:
StatusCode : 200
StatusDescription : OK
Content : <!doctype html>
<html>
<head>
<title>Example Domain</title>
<meta charset="utf-8" />
<meta http-equiv="Content-type" content="text/html;
charset=utf-8" />
<meta name="viewport" conten...
RawContent : HTTP/1.1 200 OK
Vary: Accept-Encoding
X-Cache: HIT
Content-Length: 1270
Cache-Control: max-age=604800
Content-Type: text/html
Date: Mon, 19 Feb 2018 16:38:28 GMT
Expires: Mon, 26 Feb 2018 16:38...
Forms :
Headers : {[Vary, Accept-Encoding], [X-Cache, HIT], [Content-Length,
1270], [Cache-Control, max-age=604800]...}
Images : {}
InputFields : {}
Links : {@{outerHTML=<a
href="http://www.iana.org/domains/example">More
information...</a>; tagName=A;
href=http://www.iana.org/domains/example}}
ParsedHtml :
RawContentLength : 1270
但问题是,我看不到发送的 headers(session 变量或用户代理)。也许它被 ...
截断了?
如何显示已发送的 headers?
Invoke-WebRequest
不存储请求 header AFAIK。如果您想要 header 中的特定值,那么它希望您使用参数 -Headers
和 -UserAgent
.
HttpWebRequest
或 WebRequest
提供更多控制。
$req = [System.Net.HttpWebRequest]::Create("http://www.whosebug.com")
$res = $req.GetResponse()
$req.Headers.Keys | % { "$_ = $($req.Headers[$_])" }
Host = whosebug.com
$req | fl Method, UserAgent, ProtocolVersion
Method : GET
UserAgent :
ProtocolVersion : 1.1