Home > php教程 > php手册 > php http post 怎么改写

php http post 怎么改写

WBOY
Release: 2016-06-06 19:43:09
Original
1134 people have browsed it

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 如何改写?

本帖最后由 xcvzzq 于 2015-09-16 12:30:18 编辑

如何把以下代码
<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"
Copy after login


转为php post代码?

写的如下,不成功
<br />
<br />
$fields = array(<br />
  "aa"  =>  "aa",<br />
     "bb"  =>  "bb"<br />
);<br />
<br />
$response = http_post_fields("http://xxx", $fields);<br />
echo $response;<br />
Copy after login

------解决思路----------------------
$fields = json_encode($fields);
------解决思路----------------------
   <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>
Copy after login

PHP如何使用http curl 传输数据
http://www.paymoon.com/index.php/2015/09/17/how-to-use-php-execute-curl/#phpcurl
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template