如何通过curl测试JSON Web API

时间:2011-12-08 07:00:55

标签: php json api curl

我需要测试API

这是我的代码: -

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$body = @file_get_contents('php://input');
$json = json_decode($body, true);

if (isset($json['email'])) {
    $email = $json['email'];


    $stmt = $db->query("SELECT count(*) as count FROM usersnew where email = '". $email."'");
    $results = $stmt->fetchall();

    $count = $results['0']['count'];

    //TODO: check in db for existing entry
    if($count==0){

        //updated to add zipcode
        $data = array(
            'name' => $json['name'],
            'email' => strtolower($json['email']),
            'password' => $json['password'],
            'phone' => $json['phone'],
            'birthday' => $json['birthday'],
            'sex' => $json['sex'],
            'optin' => $json['opt_in'],
            'zipcode' => $json['zip'],
            'partnerid' => 'app001'

        );

我正在尝试的是

curl -H "Content-Type: application/json" -d '{"version":"0"}'

但在这种情况下没有输出我认为-d可能会有所不同(我想是这样)

帮帮我

1 个答案:

答案 0 :(得分:1)

看一看 this发帖。 我确定你要包含你想要发布的实际http:// url。同样根据该链接,尝试包括-X POST