开发者

PHP: get contents of the aspx file [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 11 years ago.

I got next problem. I need to get HTML of several pages. All works great with PHP functions file() or file_get_contents() or CURL.

But doesn't work for one URL!! Here it is (of course, I try to get HTML of non-shortened URL).

I tried all, nothing helps. I can open this page in browswer, it returns 200 status, but... I can't get it's contents! It returns 500 error, when I try to get it via CURL:

Stack Trace:

[NullReferenceException: Object reference not set to an instance of an object.]
   ASP.ypDetectClass..ctor() +47
   ASP.immigration_immigrating_ainp_application_forms_aspx..ctor() +26
   __ASP.FastObjectFactory_app_web_obqstzij.Create_ASP_immigration_immigrating_ainp_application_forms_aspx() +20
   System.Web.Compilation.BuildResultCompiledType.CreateInstance() +32
   System.Web.Compilation.BuildManager.CreateInstanceFromVirtualPath(VirtualPath virtualPath, Type requiredBaseType, HttpContext context, Boolean allowCrossApp, Boolean noAssert) +119
   System.Web.UI.PageHandlerFactory.GetHandlerHelper(HttpContext context, String requestType, VirtualPath virtualPath, String physicalPath) +33
   System.Web.UI.PageHandlerFactory.System.Web.IHttpHandlerFactory2.GetHandler(HttpContext context, String requestType, VirtualPath virtualPath, String physicalPath) +40
   System.Web.HttpApplication.MapHttpHandler(HttpContext context, String requestType, VirtualPath path, String pathTranslated, Boolean useAppConfig) +160
   System.Web.MapHandlerExecutionStep.System.Web.HttpApplication.IExecu开发者_开发技巧tionStep.Execute() +93
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155


Version Information: Microsoft .NET Framework Version:2.0.50727.3623; ASP.NET Version:2.0.50727.3618 " 


You must send a User-Agent HTTP Header in the HTTP request.

Using cURL, you can set the CURLOPT_USERAGENT option. This works:

$ch = curl_init();
curl_setopt( $ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (X11; U; Linux i686; pt-BR; rv:1.9.2.18) Gecko/20110628 Ubuntu/10.04 (lucid) Firefox/3.6.18' );
curl_setopt( $ch, CURLOPT_URL, 'http://albertacanada.com/immigration/immigrating/ainp-application-forms.aspx' );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
$result = curl_exec ( $ch );
curl_close ( $ch );
echo $result;

Check http://php.net/manual/en/function.curl-setopt.php and this user contributed note too: http://www.php.net/manual/en/function.curl-setopt.php#10692


I am able to retrieve the contents of the page with the command line curl. So it is very likely that you need to set a user agent in your script.

curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜