我尝试使用powershell发送POST请求,以便从执行以下脚本的页面获取数据:
$searchPage = Invoke-WebRequest -Uri "http://www.oncf.ma/PrixEtReservation/Pages/BilletsNormaux.aspx"
$searchForm = $searchPage.Forms[0]
$searchForm.Fields.ctl00_ctl19_g_7591ec74_3f19_4144_8b7f_884234b48fc8_ctl00_txtNombreAdult = "1"
$searchForm.Fields.ctl00_ctl19_g_7591ec74_3f19_4144_8b7f_884234b48fc8_ctl00_txtNombreEnfants = "0"
$searchForm.Fields.ctl00_ctl19_g_7591ec74_3f19_4144_8b7f_884234b48fc8_ctl00_dtcDepart_dtcDepartDate = "19/01/2017"
$searchPage = Invoke-WebRequest -Uri "http://www.oncf.ma/PrixEtReservation/Pages/BilletsNormaux.aspx" -Method POST -Body $searchForm.Fields
但是我收到了这个错误:
Invoke-WebRequest : Forbidden
You don't have permission to access /PrixEtReservation/Pages/BilletsNormaux.aspx on this server.
At C:\Users\abdelouhabe\Desktop\Oncf2.ps1:56 char:19
+ $searchPage = Invoke-WebRequest -Uri "http://www.oncf.ma/PrixEtReservation/P ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
我甚至填写了表格中的所有其他字段,但我仍然得到同样的错误。 此外,我尝试使用Postman谷歌浏览器扩展程序发送POST请求,我收到此错误:
403 Forbidden You don't have permission to access /PrixEtReservation/Pages/BilletsNormaux.aspx on this server.
非常感谢您的帮助!