我有一段代码如下:
$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-RestMethod
生成以下异常:
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 : {}
帐户名称(thing \ BSTNTZ-MTRFKR)中的反斜杠似乎是罪魁祸首。我使用[System.Uri]::EscapeUriString()
使用%5c编码反斜杠。是否有其他技巧可以在URI中添加黑名单?
以下链接将带您进入我正在调用的API的API参考。