当我使用以下命令时:
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
但问题是,我看不到发送的标头(会话变量或用户代理)。也许它会被...
截断?
如何显示已发送的标题?
答案 0 :(得分:3)
Invoke-WebRequest
不存储请求标头AFAIK。如果您希望标题中包含特定值,则希望您使用参数-Headers
和-UserAgent
指定它们。
HttpWebRequest
或WebRequest
会提供更多控制权。
$req = [System.Net.HttpWebRequest]::Create("http://www.stackoverflow.com")
$res = $req.GetResponse()
$req.Headers.Keys | % { "$_ = $($req.Headers[$_])" }
Host = stackoverflow.com
$req | fl Method, UserAgent, ProtocolVersion
Method : GET
UserAgent :
ProtocolVersion : 1.1