提问人:AICoding 提问时间:11/11/2023 最后编辑:mickmackusaAICoding 更新时间:11/12/2023 访问量:85
从端口 88 上的 URL 提取 JSON 数据时出现问题
Problems with fetchin JSON data from URL on port 88
问:
我有生成JSON结果的IPTV的URL。
URL 是(它只有 24 小时线,所以它会在任何人造成任何伤害之前过期)
http://mytv-extra.com:88/player_api.php?username=4240670294&password=0301902562&action=get_live_streams&category_id=3045
在浏览器中查看它时,它会显示 JSON 结果,如下所示
0
num 1
name "##### PL - POLONIA#####"
stream_type "live"
stream_id 400160541
stream_icon "https://lo1.in/pol/flg.png"
epg_channel_id null
added "1620254399"
is_adult null
category_id "3045"
custom_sid "3045"
tv_archive 0
direct_source ""
tv_archive_duration 0
1
num 2
name "PL - TVP 4K"
stream_type "live"
stream_id 117574
stream_icon "https://lo1.in/pol/tvp.png"
epg_channel_id "tvp.pl"
added "1594210172"
is_adult null
category_id "3045"
custom_sid "3045"
tv_archive 0
direct_source ""
tv_archive_duration 0`
但是在为它编写 cURL 以获取结果时,我得到了这个
数组 ( [url] => http://mytv-extra.com:88/player_api.php?username=4240670294&password=0301902562&action=get_live_streams&category_id=3045 [content_type] => [http_code] => 0 [header_size] => 0 [request_size] => 0 [filetime] => -1 [ssl_verify_result] => 0 [redirect_count] => 0 [total_time] => 1.025351 [namelookup_time] => 0.005573 [connect_time] => 0 [pretransfer_time] => 0 [size_upload] => 0 [size_download] => 0 [speed_download] => 0 [speed_upload] => 0 [download_content_length] => -1 [upload_content_length] => -1 [starttransfer_time] => 0 [redirect_time] => 0 [redirect_url] => [primary_ip] => [certinfo] => 数组 ( ) [primary_port] => 0 [local_ip] => [local_port] => 0 [http_version] => 0 [协议] => 0 [ssl_verifyresult] => 0 [方案] => [appconnect_time_us] => 0 [connect_time_us] => 0 [namelookup_time_us] => 5573 [pretransfer_time_us] => 0 [redirect_time_us] => 0 [starttransfer_time_us] => 0 [total_time_us] => 1025351 ) 卷曲错误:1025 毫秒后无法连接到 mytv-extra.com 端口 88:无法连接到服务器
这是我的代码
<?php
$url = "http://mytv-extra.com:88/player_api.php?username=4240670294&password=0301902562& action=get_live_streams&category_id=3045";
ch = curl_init();
// Set the URL
curl_setopt($ch, CURLOPT_URL, $url);
// Set other cURL options
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// Set custom headers, including Access-Control-Allow-Credentials
$headers = [
'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/119.0',
'Access-Control-Allow-Credentials: true',
];
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
// Execute cURL session and fetch the response
$response = curl_exec($ch);
// Get cURL information for debugging
$info = curl_getinfo($ch);
print_r($info);
// Check for cURL errors
if ($response === false) {
echo 'Curl error: ' . curl_error($ch);
} else {
echo $response;
}
// Close cURL session
curl_close($ch);
?>
我已经成功地为不同的 URL 创建了 cURL,但不是这个,我已经尝试了我能做的一切,从早上 6 点开始就在线寻找答案,即使是 AI 也无能为力。与提供商交谈,他们不限制任何事情
答:
这段代码对我有用:
<?php
ini_set('display_errors', '1');
ini_set('display_startup_errors', '1');
error_reporting(E_ALL);
$apiUrl = 'http://mytv-extra.com:88/player_api.php?username=4240670294&password=0301902562&action=get_live_streams&category_id=3045';
$ch = curl_init($apiUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$response = curl_exec($ch);
if ($response === FALSE) {
$error = curl_error($ch);
echo 'Error retrieving data: ' . $error;
} else {
$data = json_decode($response, TRUE);
echo '<pre>';
print_r($data);
echo '</pre>';
}
curl_close($ch);
请注意,我从 URL 中删除了空格。使用其中的空格时,我收到一条错误消息。
输出如下所示:
Array
(
[0] => Array
(
[num] => 1
[name] => ##### PL - POLONIA#####
[stream_type] => live
[stream_id] => 400160541
[stream_icon] => https://lo1.in/pol/flg.png
[epg_channel_id] =>
[added] => 1620254399
[is_adult] =>
[category_id] => 3045
[custom_sid] => 3045
[tv_archive] => 0
[direct_source] =>
[tv_archive_duration] => 0
)
[1] => Array
(
[num] => 2
[name] => PL - TVP 4K
[stream_type] => live
[stream_id] => 117574
[stream_icon] => https://lo1.in/pol/tvp.png
[epg_channel_id] => tvp.pl
[added] => 1594210172
[is_adult] =>
[category_id] => 3045
[custom_sid] => 3045
[tv_archive] => 0
[direct_source] =>
[tv_archive_duration] => 0
)
...............
评论
Error retrieving data: Failed to connect to mytv-extra.com port 88 after 1055 ms: Couldn't connect to server
&password=0301902562& <... lots of spaces ...> action=get_live_streams
echo 'HTTP code: . curl_getinfo($ch, CURLINFO_HTTP_CODE);
评论
CURLOPT_PORT
curl_setopt($ch, CURLOPT_PORT, 88);
ch = curl_init();
$ch = curl_init();