php Mengirim dan menerima数据JSON dengan PHP cURL
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php Mengirim dan menerima数据JSON dengan PHP cURL相关的知识,希望对你有一定的参考价值。
<?php
//API URL
$url = 'http://www.contohweb.com/api';
//create a new cURL resource
$ch = curl_init($url);
//setup request to send json via POST
$data = array(
'username' => 'jurnalweb',
'password' => 'password123456'
);
$payload = json_encode(array("user" => $data));
//attach encoded JSON string to the POST fields
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
//set the content type to application/json
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
//return response instead of outputting
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
//execute the POST request
$result = curl_exec($ch);
//close cURL resource
curl_close($ch);
//Output response
echo "<pre>$result</pre>";
//get response
$data = json_decode(file_get_contents('php://input'), true);
//output response
echo '<pre>'.$data.'</pre>';
以上是关于php Mengirim dan menerima数据JSON dengan PHP cURL的主要内容,如果未能解决你的问题,请参考以下文章
php Ajouter un lien de sous menu dans l'admin vers unetaxoponalnalisée
HTML,PHP:Recuperer simplement les checkbox cochÃe dans une liste de checkbox
php sql在选中复选框时获取查询
xml ROUTE REWRITING DANS IIS
初探DAN
php mysql 查询