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