我需要將此「正常」捲曲字符串轉換爲php捲曲。此命令測試,以從殼工作:如何在json中使用curl放入php中?
curl -XPUT http://foo/monitors/1.json -d "Monitor[Name]=test1"
我已經看過了很多TUTS和例子,但我嘗試到目前爲止都石沉大海。這是我試過的最新消息:
$data = array("Name" => "test1");
$payload = json_encode(array("Monitor"=> $data));
$url = 'hxxp://foo/monitors/1.json';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($ch, CURLOPT_POSTFIELDS,$payload);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch)
也是我試圖把對被格式化像這樣JSON:
{"monitor":{"Monitor":{"Id":"1","Name":"test","Type":"Remote","Funct.....
感謝
*有更多的電流信息更新
請參閱[重複](http://stackoverflow.com/questions/11079135/how-to-post-json-data-with-php-curl)問題。 – kuldipem
對不起,我不確定你的意思? – voldsomenterprise
有一個問題與您的問題相同,可以幫助您解決問題。問題鏈接是[問題](http://stackoverflow.com/questions/11079135/how-to-post-json-data-with-php-curl) – kuldipem