PHP:获取aspx文件的内容

发布于 2024-11-29 00:53:05 字数 1711 浏览 1 评论 0原文

我遇到了下一个问题。我需要获取几个页面的 HTML。所有这些都可以与 PHP 函数 file() 或 file_get_contents() 或 CURL 配合使用。

但对一个 URL 不起作用! 这里(当然,我尝试获取非缩短的网址)。

我尝试了一切,没有任何帮助。我可以在浏览器中打开此页面,它返回 200 状态,但是...我无法获取其内容!当我尝试通过 CURL 获取它时,它返回 500 错误

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.IExecutionStep.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 " 

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.IExecutionStep.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 " 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

青瓷清茶倾城歌 2024-12-06 00:53:05

您必须在 HTTP 请求中发送 User-Agent HTTP 标头

使用 cURL,您可以设置 CURLOPT_USERAGENT 选项。这有效:

$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;

检查 http://php.net/manual/en/function.curl -setopt.php 并且该用户也贡献了注释:http://www.php.net/manual/en/function.curl-setopt.php#10692

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

浪漫之都 2024-12-06 00:53:05

我可以使用命令行 curl 检索页面的内容。因此,您很可能需要在脚本中设置用户代理。

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

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)");
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文