【发布时间】:2018-03-22 15:39:18
【问题描述】:
我正在尝试在 powershell 上转换 curl 命令。 我不明白如何在正文中传递数据“声明命名空间”。
批量 CURL 代码:
@echo off
@for /F "usebackq delims=*" %%i IN (`@WHERE /R "C:\Program Files" curl`) DO @set CURL=%%i
@IF NOT DEFINED CURL echo [101;93m Enable to find CURL. Please verify installation in "C:\Program Files" (C:\Programmes) [0m && goto end
@echo curl found on ^<%CURL%^>
@echo Req XQuery ...
@call "%CURL%" -k -u xxxx:xxxxx -H "Content-Type: application/xquery" -d "declare namespace pncf = \"ns.innes.plugncast.frontals\";pncf:getDevicesWithStatus()" --url "https://localhost/.db/frontalsdb" > return.xml
:END
@pause
我的 Powershell Invoke-WebRequest 代码:
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
$user = "xxxx"
$pass = "xxxx"
$pair = "${user}:${pass}"
$bytes = [System.Text.Encoding]::ASCII.GetBytes($pair)
$base64 = [System.Convert]::ToBase64String($bytes)
$basicAuthValue = "Basic $base64"
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add('Authorization',$basicAuthValue)
$Body = @{
"declare namespace pncf" = '"ns.innes.plugncast.frontals";pncf:getDevicesWithStatus()'
}
$result = Invoke-WebRequest -uri "https://localhost/.db/frontalsdb" -Headers $headers -ContentType application/xquery -Body $Body -Method POST
批处理脚本检索 XML 并将其存储在 result.xml 中。 powershell 脚本返回:
Invoke-WebRequest : http://www.w3.org/2005/xqt-errors XPST0003 static core 1 25 1 26
Au caractère C:\test.ps1:29 : 11
+ $result = Invoke-WebRequest -uri "https://localhost/.db/frontalsdb ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation : (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebEx
ception
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
【问题讨论】:
标签: xml powershell curl https xquery