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

问题描述 投票:0回答:1

我有生成 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 来获取结果时,我得到了这个

Array ( [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] => Array ( ) [primary_port] => 0 [local_ip] => [local_port] => 0 [http_version] => 0 [protocol] => 0 [ssl_verifyresult] => 0 [scheme] => [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 ) Curl error: Failed to connect to mytv-extra.com port 88 after 1025 ms: Couldn't connect to server

这是我的代码

<?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 点开始就一直在线寻找答案,即使人工智能也无法提供帮助。与提供商交谈,他们没有限制任何内容

php arrays json curl php-curl
1个回答
0
投票

这段代码对我有用:

<?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 中的空格。由于其中有空格,我收到一条错误消息。

© www.soinside.com 2019 - 2024. All rights reserved.