AMAN
AMAN

Reputation: 1

PHP post data with parameters

I AM trying to get a JSON file from a another site and for this I am trying to make a post request but I am not able to get a JSON data. I am sharing my PHP code and CURL data please tell me where is problem and why it is not working

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");

?>

And curl

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"

Upvotes: 0

Views: 77

Answers (1)

Prabhjot Singh Kainth
Prabhjot Singh Kainth

Reputation: 1861

Just replace your CURL code with this:

$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);

Upvotes: 2

Related Questions