> php教程 > php手册 > 본문

php http post 怎么改写

WBOY
풀어 주다: 2016-06-06 19:43:09
원래의
1086명이 탐색했습니다.

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"
로그인 후 복사


转为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 />
로그인 후 복사

------解决思路----------------------
$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>
로그인 후 복사

PHP如何使用http curl 传输数据
http://www.paymoon.com/index.php/2015/09/17/how-to-use-php-execute-curl/#phpcurl
관련 라벨:
원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 추천
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!