Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Powershell Invoke WebRequest时设置所有标头_Powershell_Fiddler - Fatal编程技术网

使用Powershell Invoke WebRequest时设置所有标头

使用Powershell Invoke WebRequest时设置所有标头,powershell,fiddler,Powershell,Fiddler,我想从网上表格下载PDF文件。我使用fiddler查找标题和帖子字段。但是,我无法使用Invoke webrequest从Firefox获取与Powershell匹配的标题 原始请求 POST http://somesight/SPLeam/EAMDisplayReportWithParamValues.asp HTTP/1.1 Host: someserver User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:27.0) Gecko/20100101

我想从网上表格下载PDF文件。我使用fiddler查找标题和帖子字段。但是,我无法使用Invoke webrequest从Firefox获取与Powershell匹配的标题

原始请求

POST http://somesight/SPLeam/EAMDisplayReportWithParamValues.asp HTTP/1.1   
Host: someserver
User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:27.0) Gecko/20100101 Firefox/27.0    
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8    
Accept-Language: en-US,en;q=0.5    
Accept-Encoding: gzip, deflate
Referer: http://someserver/SPLeam/EAMPickParamValues.asp?plant=01&reportuser=reports&reportuserpw=pw&ReportName=SPLEAM%5CMNT+%2D+MM+Tracking+Rpt%2Erpt
Cookie: ASPSESDFSDIDSSQAQBQC=APHPHMNCHIECSFSSPOIKBDCAM`    
Connection: keep-alive    
Content-Type: application/x-www-form-urlencoded    
Content-Length: 132

Text0=12%2F1%2F2013&Text1=12%2F31%2F2013&Text2=MESGI&Drop2=MESCI&Text3=01&Text4=&Drop4=&Text5=R&Text6=N&cmdSaveParameters=Run+Report
POWERSHELL

POST http://someserver/SPLeam/EAMPickParamValues.asp?plant=01&reportuser=reports&reportuserpw=pw&ReportName=SPLEAM%5CMNT+%2D+MM+Tracking+Rpt%2Erpt HTTP/1.1
User-Agent: Mozilla/5.0 (Windows NT; Windows NT 6.1; en-US) WindowsPowerShell/3.0
Content-Type: application/x-www-form-urlencoded
Host: someserver
Content-Length: 129
Connection: Keep-Alive
cmdSaveParameters=Run%2bReport&Text3=01&Text5=R&Text1=12%252F31%252F2013&Drop2=MI&Text2=MI&Text4=&Text6=N&Text0=12%252F1%252F2013
我把它当作
$f=invoke webrequest-uri$url-UserAgent$UserAgent-method Post-Body$param


如何使Powershell的请求与Firefox发送的请求相匹配?

.NET的HTTPWebRequest对象对
Accept
Referer
头具有单独的属性;您必须手动设置这些属性,而不是尝试直接添加标题


(这些标题限制部分出于安全目的;部分信任代码无法设置属性)。

您的$url不应该设置为
http://somesight/SPLeam/EAMDisplayReportWithParamValues.asp
为了匹配工作示例?此外,请尝试将表单正文放入哈希表中以获得正确的HTML编码,例如,
-body@{Text0='12/1/2013';…;cmdSaveParameters='Run+Report'}
正文位于哈希表中,与您描述的一样。URL将转到标头中描述的referer URL。我想使用原始URL,但无法在标题选项中添加referer。我犯了一个错误。也无法将Accept添加到标头。另一种单独添加它们的方法?如何手动设置它们并将它们合并到invoke webrequest?哪个版本的Powershell?请参阅,例如,这不适用于Invoke WebRequest。PowerShell不会公开HttpWebRequest的那些属性。相反,您需要设置Headers参数,该参数采用IDictionary参数。