当前位置: 旋风说(旋风PHPer分享网)> 技术文章> 正文
接收的文件代码如下:
1 | 代码下载链接: https: //pan.baidu.com/s/1BKmhKrmtkOqInw-hHik7tA 提取码: m8c4 |
也可以直接复制post.php:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | <?php header( 'Content-type:text/html;charset=utf-8' ); function http_post_data( $url , $data ) { $data_string = json_encode( $data ); $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 ); } $url = "http://a.com/dopost.php" ; $data = array ( 'id' =>12, 'tel' => '18500132000' , 'name' => '狗蛋' ); $response = http_post_data( $url , $data ); print_r( $response ); |
dopost.php代码:
1 2 3 4 5 6 | <?php header( 'Content-type:text/html;charset=utf-8' ); $content = file_get_contents ( "php://input" ); $content = json_decode( $content ,true); //在这里可以进行数据处理 print_r( $content ); |
当您发现内容错误或代码bug,以及下载链接无法使用等,请点击屏幕右下角的上报错误来进行提交,我们会尽快修正。
本程序所有源码和工具完全免费,当本网站内容如果侵犯了您的权益,请联系我们,我们会尽快处理,感谢您的合作。
上一篇: mysql默认引擎不是innodb?
相关文章
评论:
文明上网理性发言,请遵守 新闻评论服务协议