curl-k或--unsecure等效于Powershell调用WebRequest不工作
我试图执行:curl-k或--unsecure等效于Powershell调用WebRequest不工作,powershell,curl,invoke-webrequest,Powershell,Curl,Invoke Webrequest,我试图执行: $postParams = @{user='myUser';password='myPass'}; Invoke-WebRequest -Uri https://MYURL -Method POST -Body $postParams; 我总是被403禁止,在ubuntu或git终端中,这就像一个符咒(使用-k或--unsecure): 或 经过一些研究,我尝试了两种解决方案: 解决方案#1: 没有工作仍然得到403禁止 解决方案#2: 也不起作用,仍然得到403禁止 我可能做错
$postParams = @{user='myUser';password='myPass'};
Invoke-WebRequest -Uri https://MYURL -Method POST -Body $postParams;
我总是被403禁止,在ubuntu或git终端中,这就像一个符咒(使用-k或--unsecure):
或
经过一些研究,我尝试了两种解决方案:
解决方案#1:
没有工作仍然得到403禁止
解决方案#2:
也不起作用,仍然得到403禁止
我可能做错了什么,有什么线索吗?由于它在ubuntu和git终端中可以正常工作,并带有
-k
或--不安全的您试图解决错误的问题--k
/--不安全的影响TLS握手,而不是内部HTTP流。最可能的解释是PowerShell以web服务器无法识别的方式格式化参数值。尝试传递与原始字符串相同的负载:-Body'{“user”:“myUser”,“pass”:“myPass”}
首先,感谢您的回答!你是说?调用WebRequest-Uri-Method-POST-Body“{user='myUser';password='myPass'}”;仍然禁止使用403,linux中的curl仍然有效…您缺少-ContentType'application/json'
,请尝试添加它,看看它是否有效。可能会禁止其他类型的请求。注意,还有Invoke RestMethod
,它可能更适合您的用例;调用WebRequest-Urihttps://MYURL -方法POST-ContentType'application/json'-Body$postParams
和$postParams=@{user='myUser';password='myPass'};调用RestMethod-Urihttps://MYURL -方法POST-ContentType'application/json'-Body$postParams代码>。。但还是得到了403分
curl -k -X POST "https://MYURL" -H "accept: */*" -H "Content-Type: application/json" -d "{ \"user\" : \"myUser\", \"password\" : \"myPass\"}"
curl -X POST "https://MYURL" -H "accept: */*" -H "Content-Type: application/json" -d "{ \"user\" : \"myUser\", \"password\" : \"myPass\"}" --insecure
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = { $true };
$postParams = @{user='myUser';password='myPass'};
Invoke-WebRequest -Uri https://MYURL -Method POST -Body $postParams;
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = { $true };
$postParams = @{user='myUser';password='myPass'};
Invoke-WebRequest -Uri https://MYURL -Method POST -Body $postParams;
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;
$postParams = @{user='myUser';password='myPass'};
Invoke-WebRequest -Uri https://MYURL -Method POST -Body $postParams;