background image

'email'=>'1353777303@gmail.com' , 
'phone'=>'1353777303' 
); 

//$post_data = implode('&',$fields);

注意:post 请求的参数要用 get 方式那样连接起来,作为字符串传递:
如:

$params

 = 'userId='.

$this

->user_id.'&auth='.

$this

->auth.'&sig='.

$this

->sig

还有跨平台的请求,curl_setopt(

$ch

, CURLOPT_FOLLOWLOCATION, 1); 

// 使用自动跳转

 

(很重要)

 

//open connection 

$ch

 = curl_init() ; 

//set the url, number of POST vars, POST data 

curl_setopt(

$ch

, CURLOPT_URL,

$url

) ; 

curl_setopt(

$ch

, CURLOPT_POST,

count

(

$fields

)) ; 

// 启用时会发送一个常规的 POST 请求,

类型为:application/x-www-form-urlencoded

 

,就像表单提交的一样。

curl_setopt(

$ch

, CURLOPT_POSTFIELDS,

$fields

); 

// 在 HTTP

中的 POST”操作。如果要传送

一个文件,需要一个@

 

开头的文件名

 
ob_start(); 
curl_exec(

$ch

); 

$result

 = ob_get_contents() ; 

ob_end_clean(); 
 

echo

 

$result

 

//close connection 

curl_close(

$ch

) ; 

 
代码如下:
 
<?php 
 

if

(

$_GET

['test']) 


print_r(

$_GET

); 


 

if

(

$_POST


print_r(

$_POST

);