从端口 88 上的 URL 提取 JSON 数据时出现问题

Problems with fetchin JSON data from URL on port 88

提问人:AICoding 提问时间:11/11/2023 最后编辑:mickmackusaAICoding 更新时间:11/12/2023 访问量:85

问:

我有生成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 json curl 托管 php-curl

评论

0赞 KIKO Software 11/11/2023
也许您必须选择端口 88 ?CURLOPT_PORT
0赞 AICoding 11/11/2023
尝试过,没有:(curl_setopt($ch, CURLOPT_PORT, 88);
0赞 Professor Abronsius 11/11/2023
无法验证所述问题。然而,上面确实有一个错别字 - 它不是ch = curl_init();$ch = curl_init();
0赞 KIKO Software 11/11/2023
我用自己的代码尝试了一下,并注意到 API 对 URL 中的空格反应不佳。当我删除空格时,它工作,用我自己的代码,而不是你的代码。
0赞 AICoding 11/11/2023
@KIKOSoftware,你能为我指出我做错的正确方向吗?我将不胜感激。

答:

0赞 KIKO Software 11/11/2023 #1

这段代码对我有用:

<?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
        )
      ...............

评论

0赞 AICoding 11/11/2023
然后我做错了什么。我已经尝试了你的代码并得到了Error retrieving data: Failed to connect to mytv-extra.com port 88 after 1055 ms: Couldn't connect to server
0赞 KIKO Software 11/11/2023
@AICoding 您可能知道,无法建立连接的原因可能有很多。您或您的托管服务提供商是否使用某种防火墙?您可能只是被 API 阻止了。可能还有更多可能的原因。
0赞 AICoding 11/11/2023
您提到您已经删除了 URL 中的空格;我很抱歉听起来很愚蠢,但哪些方面?我看不到任何空格。
0赞 KIKO Software 11/11/2023
@AICoding 在您的问题中,URL 如下所示:.我怀疑这是问题中的错别字,并且不存在于您实际使用的代码中。&password=0301902562& <... lots of spaces ...> action=get_live_streams
0赞 KIKO Software 11/11/2023
@AICoding 也许您可以从 HTTP 错误代码中获取有关您遇到的问题的更多信息?只需在 cURL 执行后添加即可。echo 'HTTP code: . curl_getinfo($ch, CURLINFO_HTTP_CODE);