【问题标题】:trying to test API using postman尝试使用邮递员测试 API
【发布时间】:2017-04-03 21:45:26
【问题描述】:

我正在尝试使用 postman 测试 api,每次尝试注册时,我都会收到“意外的 e”。 真的不知道发生了什么 这是我的代码:

$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;
}
});

【问题讨论】:

  • postman 中的帖子正文是什么样的?你得到什么样的回应? 401? 403? 500?

标签: php api postman


【解决方案1】:

"unexpected e" 发生是因为 Postman 期望输出是 JSON 响应。

收到回复后,点击“原始”或“预览”标签。或者从下拉菜单中选择其他格式之一。您将看到其余的响应。

【讨论】:

    猜你喜欢
    • 2021-05-12
    • 2019-05-14
    • 2017-05-19
    • 2017-12-17
    • 2022-07-28
    • 2019-11-01
    • 1970-01-01
    • 2018-09-15
    相关资源
    最近更新 更多