Home > Backend Development > PHP Tutorial > PHP中 GET 与 POST

PHP中 GET 与 POST

WBOY
Release: 2016-06-23 13:42:42
Original
783 people have browsed it

GET 数据请求

<span style="font-size:18px;">$url = "http://www.xxxx.com?user=111";$ch = curl_init();curl_setopt($ch, CURLOPT_URL, $url);curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);curl_setopt($ch, CURLOPT_HEADER, 0);$out = curl_exec($ch);curl_close($ch);$obj = json_decode($out);print $obj;</span>
Copy after login


POST 数据发送

<span style="font-size:18px;">$url = "http://www.xxxx.com?user=111";$post_data = "somedata";$ch = curl_init();curl_setopt($ch, CURLOPT_URL, $url);curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);curl_setopt($ch, CURLOPT_HEADER, 0);curl_setopt($ch , CURLOPT_POST , 1 ) ;curl_setopt($ch , CURLOPT_POSTFIELDS , $post_data ) ;$out = curl_exec($ch);curl_close($ch);$obj = json_decode($out);print $obj;</span>
Copy after login



curl_setopt  主要是这个方式的使用 千变万化。

http://php.net/manual/zh/function.curl-setopt.php 可以去文档中去 找寻更多的选项。

有一次还用到 这两个 选项

<span style="font-size:18px;">        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);        curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,false);</span>
Copy after login
反正在 POST不到数据的时候,要多看看选项。


POST 数据接收

<span style="font-size:18px;">$post_data =  file_get_contents("php://input");$post_data = trim($post_data);print $post_data;</span>
Copy after login


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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template