0

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"

3
  • Your question is not clear, kindly explain it more. Commented Nov 27, 2019 at 6:45
  • Please edit my PHP code so that I can get same response like curl code is giving Commented Nov 27, 2019 at 6:48
  • I have answered the question, kindly check. Commented Nov 27, 2019 at 6:56

1 Answer 1

2

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);
Sign up to request clarification or add additional context in comments.

2 Comments

doesn't work due to certificate error: Error:SSL certificate problem: unable to get local issuer certificate
you need to add additional options for dealing with SSL ~ CURLOPT_CAINFO,CURLOPT_SSL_VERIFYHOST etc

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.