[英]Invoke-RestMethod : The remote server returned an error: (400) Bad Request. Azure AAD add group member
[英]powershell: invoke-restmethod : The remote server returned an error: (400) Bad Request
我正在尝试从电源 shell 创建 Rest API,当我尝试运行脚本时出现以下错误。
我将把脚本和错误也。 太感谢了 !
脚本:
#Skip SSL Errors
add-type @"
using System.Net;
using System.Security.Cryptography.X509Certificates;
public class TrustAllCertsPolicy : ICertificatePolicy {
public bool CheckValidationResult(
ServicePoint srvPoint, X509Certificate certificate,
WebRequest request, int certificateProblem) {
return true;
}
}
"@
[System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy
$url = 'http://github.fuze.org/api/Lists/GetList'
$acctname = 'administartor'
$password = 'M00nd4t'
$ContentType = 'application/json'
$body = @"
{
"faceid": "431494039483185",
"Id": "7647484953",
"r": "1444",
"session":=""
}
"@
$encodedCredentials = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes("$($acctname):$($password)"))
$headers = @{
'Authorization' = "Basic $encodedCredentials"
'Accept' = 'application/json'
'Content-Type' = 'application/json'
}
$var = invoke-restmethod -Uri $url -Method POST -Body $body -Headers $headers -ContentType "application/json" -UseBasicParsing
标题:
Name Value
---- -----
Contenttype appliaction/json
Accept application/json
Authorization Basic XXX=
错误:
invoke-restmethod : The remote server returned an error: (400) Bad Request.
At line:37 char:8
+ $var = invoke-restmethod -Uri $url -Method POST -Body $body -Headers ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Command
错误的请求错误通常意味着正在发送的有效负载的格式不正确。 尝试将 body 更改为:
$body = @'
{
"faceid": "431494039483185",
"Id": "7647484953",
"r": "1444",
"session":""
}
'@
查看HTTP 返回代码的类型。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.