[英]PHP JSON Curl issue
所以我試圖使用CURL獲得JSON返回值,但是我一直得到NULL值。
POST變量{mgf = userData; apiKey = 123455678qwertyui}
<?
$data = json_encode(array(
"mgf" => "userData",
"apiKey" => "123455678qwertyui"
));
$data_string = json_encode($data);
$ch = curl_init('http://www.mgf.ltd.uk/software-test/api.php');
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);
$result = json_decode($result);
var_dump($result);
?>
您正在重復此json_encode
現在就刪除一個,像這樣$data_string = $data;
在這里試試
<?php
$data = array(
"mgf" => "userData",
"apiKey" => "123455678qwertyui"
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://www.mgf.ltd.uk/software-test/api.php');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "mgf=" . $data["mgf"] . "&apiKey=" . $data["apiKey"] );
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$server_output = curl_exec ($ch);
curl_close ($ch);
var_dump($server_output);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.