我在Stack Overflow上查找了很多以找到对我的问题的答案,但根本不能。我试图发布以下JSON使用PHP cURL POST JSON并显示JSON响应
<?php
$data_string = '{
"jsonrpc": "2.0",
"method": "login",
"id": 1,
"params": {
"params": {
"username": "4321",
"password": "1234"
}
}
}';
$ch = curl_init('https://domain.com');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string))
);
$result = curl_exec($ch);
echo $result;
?>
我没有得到任何回应,即使它可以正常使用jQuery和AJAX。当我检查Chrome的开发人员工具时,该方法是GET,这很奇怪,因为我在代码中将其设置为POST。
任何想法我做错了什么?
什么......... – dbf