2017-04-03 134 views
1

我正在嘗試使用郵差測試api,每次嘗試註冊時我都會收到「意外的e」。 真的不知道是怎麼回事 這裏是我的代碼:試圖使用郵遞員測試API

$app->post('/signup', function() { 
$app = \Slim\Slim::getInstance(); 
$name = $app->request()->post('name'); 
$email = $app->request()->post('email'); 
$pass = $app->request()->post('pass'); 
$app->response->setStatus(200); 
$app->response()->headers->set('Content-Type', 'application/json'); 
try 
{ 
$db = getDB(); 
$sth = $db->prepare("select count(*) as count from user WHERE email=:email"); 
$sth->bindParam(':email', $email, PDO::PARAM_INT); 
$sth->execute(); 
$row = $sth->fetch(); 

if($row['count']>0){ 
$output = array(
'status'=>"0", 
'operation'=>"student already registered" 
); 
echo json_encode($output); 
$db = null; 
return; 
} 
else{ 

//這裏我嘗試插入值到我的數據庫。

$sth = $db->prepare("INSERT INTO user (name, email,password) 
VALUES(:name,:email,:pass)"); 
$sth->bindParam(':name', $name, PDO::PARAM_INT); 
$sth->bindParam(':email', $email, PDO::PARAM_INT); 
$sth->bindParam(':pass', $pass, PDO::PARAM_INT); 
$sth->execute(); 
$output = array(
'status'=>"1", 
'operation'=>"success" 
); 
echo json_encode($output); 
$db = null; 
return; 
} 

} 
catch(Exception $ex){ 
echo $ex; 
} 
}); 
+0

你的帖子在郵遞員身上看起來怎麼樣?你得到什麼樣的迴應? 401? 403? 500? –

回答

0

「意外的e」發生是因爲郵差希望輸出爲JSON響應。

當您收到回覆時,請點擊「原始」或「預覽」標籤。或者從下拉菜單中選擇其他格式之一。你會看到其餘的迴應。

choose Raw, Preview or the drop down