首页 > 解决方案 > PHP 发布带参数的数据

问题描述

我正在尝试从另一个站点获取 JSON 文件,为此我正在尝试发出发布请求,但我无法获取 JSON 数据。我正在分享我的 PHP 代码和 CURL 数据,请告诉我问题出在哪里以及为什么它不起作用

PHP

<?php

$a="liveclasses";
$b="playvod";
$c ="mod=liveclasses&ack=playvod&stream=https%3A%2F%2Fslhdovces.toprankers.com%2Fbharthiconcept%2F1128732%2F1128732-pr-BIOLOGYbyLavkushpandeysirClass21-bharthiconcept-1573820502927%2F1128732-pr-BIOLOGYbyLavkushpandeysirClass21-bharthiconcept-1573820502927.m3u8";

$url = 'https://live.bharticoncept.com/route?route=common%2Fajax';

$data = array('mod' => $a,'ack' =>$b, 'stream' => $c);
$options = array(
    'http' => array(
        'Host' => "live.bharticoncept.com",       


        'header'  => "Content-type: application/x-www-form-urlencoded\r\n",
        'cookie'=>"tr_live_bharticoncept_com=so1ofdpkcleeshaq5dsevteia0",
        'method'  => 'POST',
        'content' => http_build_query($data)

    )

);

$context  = stream_context_create($options);
$result = file_get_contents($url, false, $context);
if ($result === FALSE) {    
}

echo("$result");

?>

和卷曲

curl -X POST -H "Host:live.bharticoncept.com" -H "content-type:application/x-www-form-urlencoded; charset=UTF-8" -H "cookie:tr_live_bharticoncept_com=so1ofdpkcleeshaq5dsevteia0" -H "content-length:255" -d 'mod=liveclasses&ack=playvod&stream=https%3A%2F%2Fslhdovces.toprankers.com%2Fbharthiconcept%2F1128732%2F1128732-pr-BIOLOGYbyLavkushpandeysirClass21-bharthiconcept-1573820502927%2F1128732-pr-BIOLOGYbyLavkushpandeysirClass21-bharthiconcept-1573820502927.m3u8' "https://live.bharticoncept.com/route?route=common%2Fajax"

标签: javascriptphphtmljson

解决方案


只需将您的 CURL 代码替换为:

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, 'https://live.bharticoncept.com/route?route=common%2Fajax');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, "mod=liveclasses&ack=playvod&stream=https%3A%2F%2Fslhdovces.toprankers.com%2Fbharthiconcept%2F1128732%2F1128732-pr-BIOLOGYbyLavkushpandeysirClass21-bharthiconcept-1573820502927%2F1128732-pr-BIOLOGYbyLavkushpandeysirClass21-bharthiconcept-1573820502927.m3u8");

$headers = array();
$headers[] = 'Host: live.bharticoncept.com';
$headers[] = 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8';
$headers[] = 'Cookie: tr_live_bharticoncept_com=so1ofdpkcleeshaq5dsevteia0';
$headers[] = 'Content-Length: 255';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$result = curl_exec($ch);
print_r($result);
if (curl_errno($ch)) {
    echo 'Error:' . curl_error($ch);
}
curl_close($ch);

推荐阅读