使用POST数据调用Restful API

时间:2014-01-15 01:49:57

标签: php rest curl restful-authentication

我试图用POST数据调用我自己的Restful API;但它不起作用!如果我在这里遗失了什么,请你告诉我吗?

我在login.php中的代码:

$ch = curl_init(); 
$UN = htmlspecialchars(strip_tags($_POST['user']));
$PWD = htmlspecialchars(strip_tags($_POST['password'], ENT_QUOTES));

$data = array('action' => 'authenticateUser',
    'username'=>$UN,
    'password'=>$PWD
        ); 


curl_setopt($ch, CURLOPT_URL, 'my URL goes Here'); 
curl_setopt($ch, CURLOPT_POST, 1); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $data); 

$response = curl_exec($ch); 

现在在索引中:

    //The following require once echo the response from my restful API( I am not sure why it does echo though!) :[{"username":"John Smith","password":"*32ewrer43","firstName":"John","lastName":"Smith"}
    require_once('includes/login.php');

    $response = json_decode($response);
    //The following line echo int(1) ! so why not my data?!
    var_dump($response);

由于

0 个答案:

没有答案