我正在尝试使用PowerShells Invoke-RestMethod
将数据发布到网址,但我不断收到此消息:
+ $response.RawContent + ~ Unexpected token '' in expression or statement. + CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException + FullyQualifiedErrorId : UnexpectedToken
我错过了某个字符串文字的转义或格式错误的引号吗?
$user = "username"
$pass = "password"
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user, $pass)))
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add('Authorization',('Basic {0}' -f $base64AuthInfo))
$headers.Add('Accept','application/json')
$headers.Add('Content-Type','application/json')
$uri = "http://myurl.com"
$params = @{
message = "hello world"
}
$response = Invoke-RestMethod -Method Post -Headers $headers -Uri $uri -Body $params
$response.RawContent
答案 0 :(得分:0)
删除$ response.RawContent并且它有效。将其更改为echo $ response以查看输出。