javascript - 无法在生产网络上卷曲网站,只能在 localhost - php 中工作
问题描述
我在 curl 网站时遇到问题:http: //hdonline.vn/phim-into-the-badlands-3-15477.html
这是真实的代码(它在本地主机中工作):
<?php
/**
* Get a web file (HTML, XHTML, XML, image, etc.) from a URL. Return an
* array containing the HTTP server response header fields and content.
*/
function get_web_page( $url )
{
$user_agent='Mozilla/5.0 (Windows NT 6.1; rv:8.0) Gecko/20100101 Firefox/8.0';
$options = array(
CURLOPT_CUSTOMREQUEST =>"GET", //set request type post or get
CURLOPT_POST =>false, //set to GET
CURLOPT_USERAGENT => $user_agent, //set user agent
CURLOPT_COOKIEFILE =>"cookie.txt", //set cookie file
CURLOPT_COOKIEJAR =>"cookie.txt", //set cookie jar
CURLOPT_RETURNTRANSFER => true, // return web page
CURLOPT_HEADER => false, // don't return headers
CURLOPT_FOLLOWLOCATION => true, // follow redirects
CURLOPT_ENCODING => "", // handle all encodings
CURLOPT_AUTOREFERER => true, // set referer on redirect
CURLOPT_CONNECTTIMEOUT => 120, // timeout on connect
CURLOPT_TIMEOUT => 120, // timeout on response
CURLOPT_MAXREDIRS => 10, // stop after 10 redirects
);
$ch = curl_init( $url );
curl_setopt_array( $ch, $options );
$content = curl_exec( $ch );
$err = curl_errno( $ch );
$errmsg = curl_error( $ch );
$header = curl_getinfo( $ch );
curl_close( $ch );
$header['errno'] = $err;
$header['errmsg'] = $errmsg;
$header['content'] = $content;
return $header;
}
$result = get_web_page('http://hdonline.vn/phim-into-the-badlands-3-15477.html');
if ( $result['errno'] != 0 )
echo 'lỗi';
if ( $result['http_code'] != 200 )
echo 'không có trang, ko có quyền';
$page = $result['content'];
print_r($page);
?>
您可以复制所有代码并创建新页面进行测试。
问题是:我将源上传到我的 VPS,这里是生产站点: https ://sharengay.com/hdonline/curlhdonline.php
它什么都不显示。
在https://sharengay.com/hdonline:
我在第一个要传递的 php 文件中添加了此代码:
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST');
header("Access-Control-Allow-Headers: X-Requested-With");
解决方案
推荐阅读
- css - 更改yii2中radiolist的css
- xml - 根据节点值批量重命名 XML 文件
- python - ImportError:没有名为解析的模块 - Python 3
- javascript - 导入已定义的 const 不会引发错误
- dart - Flutter中如何对齐Dialog底部的两个按钮
- c# - Windows 窗体和缩放
- python - 函数未在 Python 中输出值
- c# - 在 C# 中使用带空格和不带空格的运算符
- python - 熊猫值错误:“时间数据'nan'与格式不匹配”,当使用“read_csv”和“date_parser”和“comment”时
- c - 如何查找 IPv6 套接字的 scope_id