PowerShell提交HTTP Request Post请求


 

提交key1=value1&key2=value2类型参数:

方法一:

$textmod="key=$key&content=$data&touser=$touser"

Invoke-WebRequest -UseBasicParsing $url  -Method POST -Body $textmod
Invoke-WebRequest -UseBasicParsing $url -ContentType 'application/x-www-form-urlencoded;charset=UTF-8' -Method POST -Body $textmod  #提交的数据中如果包含符号&使用%26代替,contentType解决中文乱码问题
 

 

方法二:

#中文和特殊符号无需特殊处理
$textmod = @{key=$key;content=$data;touser=$touser}
Invoke-WebRequest -UseBasicParsing $url -Method POST -Body $textmod  

 

 

提交json类型参数,未测试

$text = @{
 "content" = $data,
 "touser" = $touser,
 "sn" = $sn } | ConvertTo-Json Invoke-WebRequest -UseBasicParsing $url -ContentType "application/json" -Method POST -Body $text

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM