javascript - 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"
解决方案
只需将您的 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);
推荐阅读
- jquery - 如何从除当前元素之外的所有元素中删除一个类?
- javascript - 以 min/max 随机分块字节
- amazon-web-services - 具有多个客户接口的微服务的正确架构
- node.js - 为什么我在第二次运行测试时在 Mongoose 中收到错误“一旦编译后无法覆盖模型”?
- javascript - 无法读取 multer 中未定义的属性“toString”
- javascript - 在 Vue.js 应用程序中的浏览器刷新时丢失数据
- go - 如何将 *rsa.PublicKey 变成可识别的密钥字符串
- ethereum - 以太坊中未处理的承诺拒绝警告
- sql-server - SQL Server 2008 透视和连接
- javascript - 从 Brightspace 上的 API 获取字段