Gehen Sie davon aus, dass die URL gedruckt ist
{"message":"123。"}
Wie kann ich diesen 123-Text mit PHP ausdrucken?
$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'];
Ich schreibe so, aber da ist nichts?
看不太懂,現(xiàn)在是https://xxx.xxx.com/xxx/list
這個網(wǎng)址,打開瀏覽器輸出了{"message":"123。"}
這段內(nèi)容?然后你要獲取123?
$res = file_get_contents('https://xxx.xxx.com/xxx/list');
$res = json_decode($res, true);
echo $res['message'];
curl請求(get|post)到的結(jié)果是什么?如果是字符串(你給出的那個)那你直接json_decode就行,如果什么都沒有,是不是你請求方式錯了,網(wǎng)頁打開有顯示那應(yīng)該是get吧