小白龙 当前在线
少尉
$bodyParams = @{ name = "Divid" age = "23" # 下面还有很多 } $body = "" foreach ($key in $bodyParams.Keys) { $value = $bodyParams[$key] $body += "$key=$value&" } $body = $body.TrimEnd('&') 复制代码
Five66 当前离线
上尉
TOP
wanghan519 当前在线
二级士官
# 创建一个有序哈希表并添加键值对 $orderedHash = [ordered]@{ key1 = "value1" key2 = "value2" key3 = "value3" } # 遍历有序哈希表 foreach ($entry in $orderedHash.GetEnumerator()) { Write-Host "$($entry.Key): $($entry.Value)" }复制代码
$bodyParams = @{ name = "Divid" age = "23" # 下面还有很多 } $body=[System.Text.StringBuilder]::new() $bodyParams.Keys.foreach({ $null=$body.append($_).append('=').append($bodyParams[$_]).append('&') }) $body.tostring(0,$body.length-1)复制代码
评分人数
$bodyParams = @{ name = "Divid" age = "23" # 下面还有很多 } [System.Collections.ArrayList] $qs_array = @() foreach ($qs in $bodyParams.GetEnumerator()) { $qs_key = [System.Web.HttpUtility]::UrlEncode($qs.Name) $qs_value = [System.Web.HttpUtility]::UrlEncode($qs.Value) $qs_array.Add("${qs_key}=${qs_value}") | Out-Null } $qs_array -join '&'复制代码