Powershell 如何在PS中使用Curl

Powershell 如何在PS中使用Curl,powershell,Powershell,我不知道如何在PowerShell中使用Curl PHP Curl外观: $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_URL, "link"); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_POST, 1);

我不知道如何在PowerShell中使用Curl

PHP Curl外观:

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_URL, "link");
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_VERBOSE, 1);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    "Key: " . $apiPublic,
    "Sign: " . $snt_header
    ));
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
我用以下方法尝试了一切:

Invoke-RestMethod -Uri link`
                  -Method 'Post'`
                  -Headers @( "Key:$apiPublic", "Sign:$sntHeader")`
                  -ContentType 'application/x-www-form-urlencoded'
如果您已经获得了“Invoke RestMethod:底层连接 已关闭:发送时发生意外错误。“将下面的行添加到脚本中,因为默认情况下Powershell将TLS1.0用于web请求。但是,如果服务器预期为1.2,则需要告诉Powershell改用1.2


您在Powershell中使用
Invoke RestMethod
尝试了什么?到底是什么问题?Invoke RestMethod-Uri link-Method'Post'-Headers@(“Key:$apiPublic”,“Sign:$sntHeader”)-ContentType'application/x-www-form-urlencoded”那么问题出在哪里?你有什么错误吗?您没有收到任何回复吗?请将您的错误消息添加到您的问题中。在输入哈希文字后缺少“=”运算符。Hasta,在我放置Tls12之后,错误发生了更改,现在我得到了服务器错误400,即使我仅放置$result=Invoke RestMethod-Uri$uriHasta,我们做到了!:)问题不正确-主体值。我修复了它,最后得到了服务器的响应。非常感谢。哦,这个值只是一个例子。无论如何,干得好。。
$uri = 'https://dsx.uk/tapi/v2/info/account'
$headers = @{
    'key' = 'foo'
    'sign' = 'bar'
}
$body = @{
    value= "baz"
}

$result = Invoke-RestMethod -Uri $uri -Method Post -Headers $headers -Body $body
$result
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12