使用Invoke RestMethod进行的REST API调用的反斜杠URL生成错误
我有一段代码,如下所示:使用Invoke RestMethod进行的REST API调用的反斜杠URL生成错误,rest,powershell,Rest,Powershell,我有一段代码,如下所示: $url = 'https://foo/accounts/thing%5CBSTNTZ-MTRFKR' $request_content_type = 'application/xml' $response_checkout = Invoke-RestMethod ` -Credential $credential ` -Method Get ` -Uri $url ` -ContentType $request_content_type Invoke rest方法
$url = 'https://foo/accounts/thing%5CBSTNTZ-MTRFKR'
$request_content_type = 'application/xml'
$response_checkout = Invoke-RestMethod `
-Credential $credential `
-Method Get `
-Uri $url `
-ContentType $request_content_type
Invoke rest方法
生成以下异常:
PSMessageDetails :
Exception : System.Net.WebException: The remote server returned an error: (404) Not Found.
at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.GetResponse(WebRequest request)
at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.ProcessRecord()
TargetObject : System.Net.HttpWebRequest
CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
ErrorDetails : Account not found: ?\thing
InvocationInfo : System.Management.Automation.InvocationInfo
ScriptStackTrace : at <ScriptBlock>, <No file>: line 1
PipelineIterationInfo : {}
psmessage详细信息:
异常:System.Net.WebException:远程服务器返回错误:(404)未找到。
位于Microsoft.PowerShell.Commands.WebRequestPSCmdlet.GetResponse(WebRequest请求)
在Microsoft.PowerShell.Commands.WebRequestPSCmdlet.ProcessRecord()中
TargetObject:System.Net.HttpWebRequest
CategoryInfo:InvalidOperation:(System.Net.HttpWebRequest:HttpWebRequest)[调用RestMethod],WebException
FullyQualifiedErrorId:WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
ErrorDetails:找不到帐户:?\thing
调用信息:System.Management.Automation.InvocationInfo
ScriptStackTrace:at,:第1行
PipelineIterationInfo:{}
帐户名(thing\BSTNTZ-MTRFKR)中的反斜杠似乎是罪魁祸首。我使用[System.Uri]::EscapeUriString()
对反斜杠进行了%5c编码。在URI中添加黑斜杠还有其他技巧吗
下面的链接将带您访问我正在调用的API的API参考
找不到帐户:?\thing
可能该服务正在从“帐户”的末尾删除任何非字母字符。(“比利”、“苏西”等)是反斜杠引起了问题。不确定该怎么办。该服务是否支持包括域在内的服务?通常,这些东西的工作方式类似于accounts?username=mtrfkr+domain=thing
etc@TheIncorrigible1,您的建议是有意义的,但不是,至少基于API的文档。URI的格式必须为:https://:18443/iam/api/1.0/restapi/environments/ac/endpoints///accounts/
。帐户名可以是任何字符串。在这种情况下,它正好有一个反斜杠。