Assume there is a URL printed out
{"message":"123。"}
How should I use php to print out this 123 text?
$request = file_get_contents('php://input');
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://xxx.xxx.com/xxx/list");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json; charset=utf-8"));
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
$data = curl_exec($ch);
curl_close($ch);
echo $data['message'];
I write like this but there is nothing?
I can’t quite understand it. Now it’s
https://xxx.xxx.com/xxx/list
. When I open the browser, it outputs{"message":"123."}
This content? And then you want to get 123?What is the result of curl request (get|post)? If it is a string (the one you gave), then you can just json_decode it. If there is nothing, is your request method wrong? If the page is opened and it is displayed, it should be get.