提交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