php - RSS 不会在 PHP 中解析(尝试过 file_get_contents、curl 和 simplexml_load_file)
问题描述
我现在完全迷路了,这是 URL 示例:
file_get_contents('http://adam-wennick.squarespace.com/actor-bro-show?format=rss');
当然,这适用于任何其他 url...但是这个,虽然它在浏览器中加载得很好,但它为file_get_contents和simplexml_load_file返回 400 ,而它为 curl 返回 200,但对象是NULL。你们有没有人遇到过这样的事情?
卷曲代码:
$rss = 'http://adam-wennick.squarespace.com/actor-bro-show?format=rss';
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $rss);
curl_setopt($ch,CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch,CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');
$output = curl_exec($ch);
解决方案
<?php
$ch = curl_init("http://adam-wennick.squarespace.com/actor-bro-show?format=rss");
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.2; WOW64; rv:17.0) Gecko/20100101 Firefox/17.0');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$result = curl_exec($ch);
print_r($result);
curl_close($ch);
输出是url的内容
推荐阅读
- java - 当我通过共享意图共享图像时,应用程序在 Android Oreo 上崩溃
- android - 哪个最好作为 Android 中的时间戳 [仅使用新的 Java.time]?LocalDateTime 还是 Instant.now()?
- javascript - 将自定义组件作为触发器传递时,语义的弹出窗口不显示
- android - 如何根据 Android 项目构建类型(生产与暂存)配置哨兵环境?
- borland-c++ - TEdit - 如果剪贴板包含特定字符串,则忽略粘贴操作
- javascript - firebase.auth().signInAnonymously() 如何维护会话?
- vba - 如何为带有幻灯片时间和标题的 PowerPoint 视频制作生成 YouTube 索引?
- sql - 如何为已创建的 PostgreSQL 表创建外键?
- tcp - tcp_retransmit_skb 的 kprobe。而不是 tcp_retransmit_skb @tcp_states,我想 kprobe __napi_schedule
- java - 过滤器不响应意图