问题
I have an ASP.NET Website and hosted on shared hosting and everything is working fine but recently I had requirement to call one page of website from php script via cURL but while executing php script via php-cgi.exe I am getting below error;
HTTP Error 403.0 - ModSecurity Action You do not have permission to view this directory or page.
Note I am able to browse that page from my browser without login to website.
What can be the possible cause for this error and could someone guide me to resolve this issue?
PHP Script
<?php
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, "http://<domainname>//<filename>.aspx");
curl_exec($curl);
curl_close($curl);
?>
Thanks in advance!
回答1:
After Analyzing issue found that error was coming due to user agent was not set in cURL request.
Updated PHP script;
<?php
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, "http://<domainname>//<filename>.aspx");
curl_setopt($curl,CURLOPT_USERAGENT,"useragentvalue");
curl_exec($curl);
curl_close($curl);
?>
来源:https://stackoverflow.com/questions/37011704/http-error-403-0-modsecurity-action-you-do-not-have-permission-to-view-this-d