我一直在尝试使用 cmd curl 来获取数据,并且 fetch 命令在 chrome 开发工具控制台中工作,但它没有使用 cmd 返回正确的结果,我在开发工具中使用了副本作为 cURL 函数,但它返回不同结果。奇怪的是,当我将副本用作 PowerShell 并在 PowerShell 7 中使用 Invoke-WebRequest 时,它得到了正确的响应。我运行开发工具的网站是https://homeaccess.saisd.org/HomeAccess/Account/LogOn?ReturnUrl=%2fhomeaccess。感谢您的任何反馈。
//The "copy as fetch" which works in dev tools console
fetch("https://homeaccess.saisd.org/HomeAccess/Account/LogOn?ReturnUrl=%2fHomeAccess%2f", {
"headers": {
"accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
"accept-language": "en-US,en;q=0.9",
"cache-control": "max-age=0",
"content-type": "application/x-www-form-urlencoded",
"sec-fetch-dest": "document",
"sec-fetch-mode": "navigate",
"sec-fetch-site": "same-origin",
"sec-fetch-user": "?1",
"upgrade-insecure-requests": "1"
},
"referrer": "https://homeaccess.saisd.org/HomeAccess/Account/LogOn?ReturnUrl=%2fHomeAccess%2f",
"referrerPolicy": "strict-origin-when-cross-origin",
"body": "__RequestVerificationToken=XM3fJKbbs7QjfVKVPFAcltMmoFRecsbXPcWbcNrop1_R4eHIHGEaZKo65p9UUpqOBTJymC20mJGKaF2P4zVM1urYf2Fv5mPHQf4q5yEw3j41&SCKTY00328510CustomEnabled=False&SCKTY00436568CustomEnabled=False&Database=10&VerificationOption=UsernamePassword&LogOnDetails.UserName=55555&tempUN=&tempPW=&LogOnDetails.Password=88888888",
"method": "POST",
"mode": "cors",
"credentials": "include"
});
//and the "copy as cURL" which doesnt return correct response in cmd
curl "https://homeaccess.saisd.org/HomeAccess/Account/LogOn?ReturnUrl=^%^2fHomeAccess^%^2f" ^
-H "Connection: keep-alive" ^
-H "Cache-Control: max-age=0" ^
-H "Upgrade-Insecure-Requests: 1" ^
-H "Origin: https://homeaccess.saisd.org" ^
-H "Content-Type: application/x-www-form-urlencoded" ^
-H "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.111 Safari/537.36" ^
-H "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9" ^
-H "Sec-Fetch-Site: same-origin" ^
-H "Sec-Fetch-Mode: navigate" ^
-H "Sec-Fetch-User: ?1" ^
-H "Sec-Fetch-Dest: document" ^
-H "Referer: https://homeaccess.saisd.org/HomeAccess/Account/LogOn?ReturnUrl=^%^2fHomeAccess^%^2f" ^
-H "Accept-Language: en-US,en;q=0.9" ^
-H "Cookie: _ga=GA1.2.1480406019.1587230747; SPIHACSiteCode=; __RequestVerificationToken_L0hvbWVBY2Nlc3M1=XncgYsOz0wLk4SEPgKwYPP23lLLCuC0uUyp6IE3BjuAy8QarbyT6_Unape_o9HP8bd3MHpcdkQr8zE3SIXedrqCNGwQEuKPlNrjqM5VFb5M1; ASP.NET_SessionId=240ee2yydcofxchrrsnqgshr" ^
--data-raw "__RequestVerificationToken=XM3fJKbbs7QjfVKVPFAcltMmoFRecsbXPcWbcNrop1_R4eHIHGEaZKo65p9UUpqOBTJymC20mJGKaF2P4zVM1urYf2Fv5mPHQf4q5yEw3j41^&SCKTY00328510CustomEnabled=False^&SCKTY00436568CustomEnabled=False^&Database=10^&VerificationOption=UsernamePassword^&LogOnDetails.UserName=55555^&tempUN=^&tempPW=^&LogOnDetails.Password=88888888" ^
--compressed