温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

使用php怎么接收和处理 post、json参数

发布时间:2021-05-18 16:57:24 来源:亿速云 阅读:232 作者:Leah 栏目:开发技术

今天就跟大家聊聊有关使用php怎么接收和处理 post、json参数,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。

1.php

<? 
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(); 
  //echo $return_content."<br>"; 
  ob_end_clean(); 
 
  $return_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); 
  // return array($return_code, $return_content); 
  return $return_content; 
 } 
 
$url = "http://127.0.0.1/2.php"; 
$data = json_encode(array('a'=>"weqweqwe", 'b'=>2));  
 
//list($return_code, $return_content) = http_post_data($url, $data); 
$aaa = http_post_data($url, $data); 
//print_r($aaa); 
echo $aaa; 
 
$ccc=json_decode($aaa); 
print_r($ccc); 
echo $ccc->b; 
 
echo "<hr>"; 
$json = '{"a":1,"b":2,"c":3,"d":4,"e":5}'; 
var_dump(json_decode($json,true)); 
  
?>

页面2,参数接收处理:

2.php

<? 
$postData = file_get_contents('php://input'); 
echo $postData; 
$data = json_encode(array('a'=>" 234 ", 'b'=>2)); 
echo $data; 
?>

PHP开发环境搭建工具有哪些

一、phpStudy,是一个新手入门最常用的开发环境。二、WampServer,WampServer也同样的也是和phpStudy一样操作简单对小白比较友好。三、XAMPP,XAMPP(Apache+MySQL+PHP+PERL)是一个功能强大的建站集成软件包;四、MAMP,MAMP分为两种MAMP和MAMP Pro for Mac。五、宝塔面板,宝塔面板是一款服务器管理软件,支持windows和linux系统。六、UPUPW,UPUPW是目前Windows平台下最具特色的Web服务器PHP套件。

看完上述内容,你们对使用php怎么接收和处理 post、json参数有进一步的了解吗?如果还想了解更多知识或者相关内容,请关注亿速云行业资讯频道,感谢大家的支持。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI