php http post 如何改写? 本帖最后由 xcvzzq 于 2015-09-16 12:30:18 编辑 如何把以下代码 curl-H"Content-type:application/json"-XPOST-d'{ "aaa":"aaa" "bb":"bb", "cc":{ "cc1":"cc1", "cc2":"cc3" } }'"http://xxx" 转为phppost代码? 写的如下,不成功
php http post 如何改写?
<br /> curl -H "Content-type: application/json" -X POST -d '{ <br /> "aaa": "aaa"<br /> "bb": "bb",<br /> "cc": {<br /> "cc1": "cc1",<br /> "cc2": "cc3"<br /> }<br /> }' "http://xxx"
<br /> <br /> $fields = array(<br /> "aa" => "aa",<br /> "bb" => "bb"<br /> );<br /> <br /> $response = http_post_fields("http://xxx", $fields);<br /> echo $response;<br />
<html><br /> <head><br /> <title>PHP 测试</title><br /> </head><br /> <body><br /> <?php<br /> $fields = array(<br /> "aa" => "aa",<br /> "bb" => "bb"<br /> );<br /> <br /> $fiel【本文来自鸿网互联 (http://www.68idc.cn)】dsdate = json_encode($fields);<br /> <br /> $ch = curl_init("http://xxx");<br /> curl_setopt($ch, CURLOPT_HEADER, "Content-type: application/json");<br /> curl_setopt($ch, CURLOPT_POST, 1);<br /> curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);<br /> curl_setopt($ch, CURLOPT_POSTFIELDS, $fieldsdate);<br /> $output = curl_exec($ch);<br /> if(curl_errno($ch)){//出错则显示错误信息<br /> print curl_error($ch);<br /> }<br /> <br /> curl_close($ch);<br /> echo $output;<br /> <br /> <br /> ?><br /> </body><br /> </html>