21,886
社区成员
发帖
与我相关
我的任务
分享
curl -H "Content-type: application/json" -X POST -d '{
"aaa": "aaa"
"bb": "bb",
"cc": {
"cc1": "cc1",
"cc2": "cc3"
}
}' "http://xxx"
$fields = array(
"aa" => "aa",
"bb" => "bb"
);
$response = http_post_fields("http://xxx", $fields);
echo $response;
<html>
<head>
<title>PHP 测试</title>
</head>
<body>
<?php
$fields = array(
"aa" => "aa",
"bb" => "bb"
);
$fieldsdate = json_encode($fields);
$ch = curl_init("http://xxx");
curl_setopt($ch, CURLOPT_HEADER, "Content-type: application/json");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fieldsdate);
$output = curl_exec($ch);
if(curl_errno($ch)){//出错则显示错误信息
print curl_error($ch);
}
curl_close($ch);
echo $output;
?>
</body>
</html>
PHP如何使用http curl 传输数据
http://www.paymoon.com/index.php/2015/09/17/how-to-use-php-execute-curl/#phpcurl
<?php
$post_data =
array(
'cclist=5AAAA',
'date=0',
'irname=',
'fullpath=',
);
$post_data = implode('&',$post_data);
$url='http://mathuat.us/check/shopavon.php';
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
ob_start();
curl_exec($ch);
$result = ob_get_contents() ;
ob_end_clean();
echo $result;
?>