欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

PHP基于curl模擬post提交json數(shù)據(jù)示例

 更新時(shí)間:2018年06月22日 11:36:50   作者:愛代碼也愛生活  
這篇文章主要介紹了PHP基于curl模擬post提交json數(shù)據(jù)操作,結(jié)合實(shí)例形式分析了php使用curl實(shí)現(xiàn)post方式提交json數(shù)據(jù)相關(guān)操作步驟與注意事項(xiàng),代碼簡(jiǎn)單實(shí)用,需要的朋友可以參考下

本文實(shí)例講述了PHP基于curl模擬post提交json數(shù)據(jù)。分享給大家供大家參考,具體如下:

這里php模擬post提交json數(shù)據(jù)操作的關(guān)鍵是在頭部設(shè)置Content-Type

<?php
header("Content-type:application/json;charset=utf-8");
$url="http://192.168.10.234:8080/uc/login/loginid";
$param=array(
  //注冊(cè)字段
  "name"=>"test001",
  "pass"=>"xxxx",
);
$data = json_encode($param);
list($return_code, $return_content) = http_post_data($url, $data);//return_code是http狀態(tài)碼
print_r($return_content);exit;
function http_post_data($url, $data_string) {
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_POST, 1);
  curl_setopt($ch, CURLOPT_URL, $url);
  curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
  curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    "Content-Type: application/json; charset=utf-8",
    "Content-Length: " . strlen($data_string))
  );
  ob_start();
  curl_exec($ch);
  $return_content = ob_get_contents();
  ob_end_clean();
  $return_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  return array($return_code, $return_content);
}

PS:這里再為大家推薦幾款比較實(shí)用的json在線工具供大家參考使用:

在線JSON代碼檢驗(yàn)、檢驗(yàn)、美化、格式化工具:
http://tools.jb51.net/code/json

JSON在線格式化工具:
http://tools.jb51.net/code/jsonformat

在線XML/JSON互相轉(zhuǎn)換工具:
http://tools.jb51.net/code/xmljson

json代碼在線格式化/美化/壓縮/編輯/轉(zhuǎn)換工具:
http://tools.jb51.net/code/jsoncodeformat

C語(yǔ)言風(fēng)格/HTML/CSS/json代碼格式化美化工具:
http://tools.jb51.net/code/ccode_html_css_json

更多關(guān)于PHP相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《php curl用法總結(jié)》、《PHP網(wǎng)絡(luò)編程技巧總結(jié)》、《PHP數(shù)組(Array)操作技巧大全》、《php字符串(string)用法總結(jié)》、《PHP數(shù)據(jù)結(jié)構(gòu)與算法教程》及《PHP中json格式數(shù)據(jù)操作技巧匯總

希望本文所述對(duì)大家PHP程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論