$url = "XXXXXXXXXXX";
// what post fields?
$fields = array(
'roll_number' => '123456',
'full_name' => 'aaaaaa',
'mother_name' => 'bbbbbbb',
'_token' => 'xxxxxxxxxxxxxxxx'
);
// build the urlencoded data
$postvars = http_build_query($fields);
// open connection
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded'));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$postvars);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
echo $response;
请求应该是post方法,数据应该是JSON编码或URL编码我已经尝试了两种,但没有一种工作
答案 0 :(得分:0)
不确定这是否是原因,但您的HTTPHEADER不应该application/json
?此外,您未将数据编码为JSON - 您可能需要将$postvars = http_build_query($fields);
更改为$postvars = json_encode($fields);
我还要看一下https://lornajane.net/posts/2011/posting-json-data-with-php-curl