简体   繁体   English

使用PowerShell调用-RemMethod

[英]Invoke-RestMethod with PowerShell

I am trying to post data to a URL using PowerShells Invoke-RestMethod however I constantly keep getting this message: 我试图使用PowerShells Invoke-RestMethod将数据发布到URL但是我不断收到此消息:

 + $response.RawContent​ + ~ Unexpected token '​' in expression or statement. + CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException + FullyQualifiedErrorId : UnexpectedToken 

Am I missing an escape of a string literal somewhere or malformed quote mark? 我错过了某个字符串文字的转义或格式错误的引号吗?

$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​

Removed $response.RawContent and it works. 删除$ response.RawContent,它的工作原理。 Changed it to echo $response to see output. 将其更改为echo $ response以查看输出。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM