卷曲发布错误

I want to get the value when I post with php CURL to this link:"https://www.turkiye.gov.tr/btk-numara-tasima" but when i try to do this, i can not get any value the code below just show me the page of the link. What is the problem?

<?php

$curl=curl_init();
$data = "txtMsisdn=5441234567&token=%7B730FD6-BC236F-6AE440-B5E1CB-338E67-00EA4E-0C7F28-58EE4A-3FA9F9-EAA9A2%7D";
curl_setopt($curl, CURLOPT_URL, "https://www.turkiye.gov.tr/btk-numara-tasima");
curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER["HTTP_USER_AGENT"]);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
curl_setopt($curl, CURLOPT_VERBOSE, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST,0);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER,0);
$content = curl_exec($curl);


if(curl_exec($curl) === false){
    echo 'Curl error: ' . curl_error($ch);
}else{
    echo 'Opatation comlated without error';
    echo $content;
}

?>

You have two issues with your code:

1) as you navigate a site with a real browser cookies are stored/updated when pages are get and sent back to the server on every subsequent request. You're not storing cookies nor sending them.

2) the token you're passing varies upon each request. It's a kind a "secret code" to validate the request.

To solve this, first you have setup curl options to manage cookies. Cookies will be stored in a small text file of your choice.

Then you have to split the task in two steps:

first step: load the page and parse the token

second step: send the post request passing the parsed token

This is some modification of your original code. You can run it from the command line too.

The only non-trivial part is extracting the token but, actually, it's just string manipulation.

<?php

// Load the page

$curl=curl_init();
curl_setopt($curl, CURLOPT_URL, "https://www.turkiye.gov.tr/btk-numara-tasima");
// curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER["HTTP_USER_AGENT"]);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_VERBOSE, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST,0);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER,0);
curl_setopt($curl, CURLOPT_COOKIEFILE, 'cookies.txt' ); // <-- read/write cookies into a text file
curl_setopt($curl, CURLOPT_COOKIEJAR,  'cookies.txt' ); // <-- read/write cookies into a text file
$content = curl_exec($curl);
curl_close( $curl );

// Parse output to extract token

$content = substr( $content, strpos( $content, '<input type="hidden" name="token" value="' ) + strlen( '<input type="hidden" name="token" value="' ) );
$token = substr( $content, 0, strpos( $content, '"' ) );
$token = urlencode( $token );

// This is the number to query

$number = '5441234567';

// Put together token and number

$data = 'txtMsisdn=' . $number . '&token=' . $token;

// Perform post request

$curl=curl_init();
curl_setopt($curl, CURLOPT_URL, "https://www.turkiye.gov.tr/btk-numara-tasima?submit");
//curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER["HTTP_USER_AGENT"]);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
curl_setopt($curl, CURLOPT_VERBOSE, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST,0);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER,0);
curl_setopt($curl, CURLOPT_COOKIEFILE, 'cookies.txt' ); // <-- read/write cookies into a text file
curl_setopt($curl, CURLOPT_COOKIEJAR,  'cookies.txt' ); // <-- read/write cookies into a text file
$content = curl_exec($curl);
curl_close( $curl );

// Parse output

$content = substr( $content, strpos( $content, '<div class="reminderContainer">' ) + strlen( '<div class="reminderContainer">' ) );
$result = substr( $content, 0, strpos( $content, '</div>' ) );

echo $result . "
";