【发布时间】:2019-04-28 17:12:28
【问题描述】:
我正在点击这个网址
https://webadmin.td90.centile-dev.com/restletrouter/v1/service/Login
然后我得到会话并传递到下面的 url
https://myistra.td90.centile-dev.com/restleroute/v1/3rdParty/AdmtiveDomain.
问题
输出
Invoke-WebRequest : Unauthorized
The request requires user authentication
You can get technical details here.
Please continue your visit at our home page.
At C:\Users\administrator\Documents\CDR.ps1:20 char:213
+ ... 'Session' | Invoke-WebRequest -Uri ("https://myistra.td90.centile-
dev ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation:
(System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
thirdParty_SESSIONID=969514241160310577; _ac958=http://10.20.100.190:8078
这是我的代码
$user = "SuperGabriel"
$pass = "SuperGabriel@2019"
$pair = "$($user):$($pass)"
$encodedCreds =
$basicAuthValue = "Basic $encodedCreds"
$PartOneHeaders = @{
"Authorization" = $basicAuthValue
"X-Application" = "3rdParty"
}
#test
$Headers =@{
"X-Application" = "3rdParty"
"Cookie"= "thirdParty_SESSIONID=7353595784495763113;"
}
$PartOneWebRequest = Invoke-WebRequest -Uri https://webadmin.td90.centile-
dev.com/restletrouter/v1/service/Login -Headers $PartOneHeaders -
ContentType "application/json" -Method POST -SessionVariable 'Session' |
Invoke-WebRequest -Uri ("https://myistra.td90.centile-
dev.com/restleroute/v1/3rdParty/AdmtiveDomain" ) -Headers $Headers -
Method Get
我已经回应了所有内容,以确保我获得了正确的信息并将其传递到正确的地方。 我已经在邮递员中测试了这个电话,它可以工作。
预期结果
[
{
"restUri": "v1/3rdParty/AdmtiveDomain/0.",
"alias": "TopLevelAdmtiveDomain",
"rootModel": "AdmtiveDomain",
"domainName": "Top-Level",
"admtiveDomainID": "0."
},
{
"restUri": "v1/3rdParty/AdmtiveDomain/0.106.",
"alias": "AdmtiveDomainSpecific",
"rootModel": "AdmtiveDomain",
"domainName": "acd-00",
"domainType": "Enterprise",
"admtiveDomainID": "0.106."
}
]
【问题讨论】:
-
你没有给
$encodedCreds一个值.. 另外.. 代码中的所有这些新换行符都是偶然的吗?管道符号后应该有什么 ('Session' |)
标签: json rest powershell http header