dongxue163536 2015-09-21 11:16
浏览 66
已采纳

php cloudant curl抱怨db已经存在

I have a curl request to a cloudant database to add a new document. However, whenever I run it, it complains the database already exists, I then have to rename the db in the url. This however, only creates a new empty database. What is wrong with my curl request from the following?

This is the code I use :

credentials = base64_encode($login.':'.$password);
    $curl = curl_init();

    curl_setopt_array($curl, array(
      CURLOPT_URL => $url,
      CURLOPT_RETURNTRANSFER => true,
      CURLOPT_ENCODING => "",
      CURLOPT_MAXREDIRS => 10,
      CURLOPT_TIMEOUT => 30,
      CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
      CURLOPT_CUSTOMREQUEST => "PUT",
      CURLOPT_POSTFIELDS => $data,
      CURLOPT_HTTPHEADER => array(
        'Authorization: Basic '.$credentials,
        "content-type: application/json"
      ),
    ));

    $response = curl_exec($curl);
    $err = curl_error($curl);

    curl_close($curl);

    if ($err) {
        if($this->debug === 1) {
            echo $err;
            var_dump($info);
        }
      return false;
    } else {
      return $response;
    }

And this is the code that uses it :

$journey_data = array(
            "name" => "name",
            "TEST" => "TESTIN TED"
            );

$this->cloudent_controller = modules::load('cloudent_integration/cloudent_integration');
        $url = "https://test.cloudant.com/fubar";
        $result = $this->cloudent_controller->createDocument($url, json_encode($journey_data));
        var_dump($result);
        die;

Yes I am using code igniter and the hmvc pattern, but those are not important details as I am getting back a response.

Response :

string(95) "{"error":"file_exists","reason":"The database could not be created, the file already exists."} "
  • 写回答

1条回答 默认 最新

  • du127953 2015-09-21 12:30
    关注

    To create a new document in a couchDB server you need to send a PUT or POST request to the url where you want the document to be saved, this means you need to specify the database and the name of the document in the url:

    https://test.cloudant.com/fubar/doc_id
    

    If you send a PUT or POST request directly to a database, as I think you do, you're asking couchDB to creat that database.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 eclipse开启服务后,网页无法打开
  • ¥30 雷达辐射源信号参考模型
  • ¥15 html+css+js如何实现这样子的效果?
  • ¥15 STM32单片机自主设计
  • ¥15 如何在node.js中或者java中给wav格式的音频编码成sil格式呢
  • ¥15 不小心不正规的开发公司导致不给我们y码,
  • ¥15 我的代码无法在vc++中运行呀,错误很多
  • ¥50 求一个win系统下运行的可自动抓取arm64架构deb安装包和其依赖包的软件。
  • ¥60 fail to initialize keyboard hotkeys through kernel.0000000000
  • ¥30 ppOCRLabel导出识别结果失败