PHP开发实例大全(提高卷) 中文完整pdf扫描版[244MB]
- // HTTP客户端 POST请求
- function http_post($url, $param) {
- $data = "";
- if (is_array($param)) {
- foreach ($param as $k=>$v) {
- $data .= '&'.$k.'='.$v;
- }
- if (strlen($data) > 0) {
- $data = substr($data, 1, strlen($data) - 1);
- }
- } else
- $data = $param;
- $ch = curl_init();
- curl_setopt( $ch, CURLOPT_URL, $url);
- curl_setopt( $ch, CURLOPT_POST, 1 );
- curl_setopt( $ch, CURLOPT_HEADER, 0 );
- curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
- curl_setopt( $ch, CURLOPT_POSTFIELDS, $data);
- $return = curl_exec($ch);
- curl_close($ch);
- return $return;
- }
- // HTTP客户端 GET请求
- function http_get($url, $param='') {
- $data = "";
- if (is_array($param)) {
- foreach ($param as $k=>$v) {
- $data .= '&'.$k.'='.$v;
- }
- if (strlen($data) > 0) {
- $data = substr($data, 1, strlen($data) - 1);
- }
- } else{
- $data = $param;
- }
- if (strlen($data) > 0){
- $url .= "?".$data;
- }
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_TIMEOUT, 30);
- curl_setopt($ch, CURLOPT_HEADER, FALSE);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,FALSE);
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,FALSE);
- $return = curl_exec($ch);
- curl_close($ch);
- return $return;
- }
转载请注明:谷谷点程序 » php curl post get提交方法