PHP:获取aspx文件的内容
我遇到了下一个问题。我需要获取几个页面的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您必须在 HTTP 请求中发送
User-Agent
HTTP 标头。使用 cURL,您可以设置
CURLOPT_USERAGENT
选项。这有效:检查 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: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
我可以使用命令行
curl
检索页面的内容。因此,您很可能需要在脚本中设置用户代理。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.