0

How to use Simple HTML DOM with input POST method?

I try to do with cUrl:

$ch = curl_init();
$timeout=5;
$data = array('teks' => '4ia17');
$data=http_build_query($data);
curl_setopt($ch,CURLOPT_URL,"http://baak.gunadarma.ac.id/jadwal/cariJadKul"); 
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
$datas = curl_exec($ch);
curl_close($ch);

echo $datas;

the problem is : problem and i try to do this too

include("simple_html_dom.php");
$request = array(
    'http' => array(
        'header' => array("Content-Type: application/x-www-form-urlencoded"),
        'method' => 'POST',
        'content' => http_build_query(array(
        'teks' => '4ia17'
        )),
    )
);
    $context = stream_context_create($request);
    $htmls = file_get_html("http://baak.gunadarma.ac.id/jadwal/cariJadKul",true, $context);
    echo $htmls; 

and the error is :

Warning: file_get_contents(http://baak.gunadarma.ac.id/jadwal/cariJadKul): failed to open stream: HTTP request failed! HTTP/1.1 500 Internal Server Error in C:\xampp\htdocs\php-youtube-dl-master\Downloader\simple_html_dom.php on line 75

can anyone please help me where lies the error is? or something i can do with?

u_mulder
  • 54,101
  • 5
  • 48
  • 64
  • Did you check your php.ini file for allow_url_fopen =1 ? – Naresh Kumar Dec 15 '17 at 09:00
  • @NareshKumar already do that. – Afif Makarim Dec 15 '17 at 09:04
  • still not working @NareshKumar – Afif Makarim Dec 15 '17 at 09:09
  • The problem is the receiving site (baak.gunadarma.ac.id). It responds with a 500 error to your post request. You can test this by setting up simple html form and submitting it. It seems the post is secured by a csrf token, which you don't supply with the request. – Yoshi Dec 15 '17 at 09:18
  • @i have modified my code and add '_token' => 'value' in my POST request but it still have 500 error. – Afif Makarim Dec 15 '17 at 10:41
  • @AfifMakarim Because the token you add is probably not the one they expect. Also they use quite a lot of cookies. I don't don't think you can fake a valid request to that site without going through some major analysis of what parameters they require (post and/or cookie). Possible that you even need to make a *pre-request* to actually get hold of the correct token/cookies). – Yoshi Dec 15 '17 at 11:32
  • @Yoshi it is not the right token? https://i.imgur.com/D8seDOf.png – Afif Makarim Dec 15 '17 at 11:46
  • @AfifMakarim The token changes presumably with every request. Read: https://en.wikipedia.org/wiki/Cross-site_request_forgery#Synchronizer_token_pattern – Yoshi Dec 15 '17 at 11:49
  • @Yoshi ah i see... so it is not possible to scrape the data unless i have permission right? :/ – Afif Makarim Dec 15 '17 at 12:17
  • @AfifMakarim I'd expect as much, yes. – Yoshi Dec 15 '17 at 12:20

0 Answers0