使用curl挂起的CouchDB POST请求

时间:2018-03-09 00:02:57

标签: curl post couchdb couchdb-mango

我在Linux服务器上安装了CouchDB v2.2.0。 我有5个数据库创建:

  • DAS
  • model_attribute_groups
  • mydemo
  • 注册表
  • verifytestdb

我可以使用下面列出的json文件的内容从Fauxton成功运行Mango查询。

我可以使用curl GET命令从另一台Linux服务器成功连接到model_attriubute_groups数据库:

curl -v http://my.server.com:5984/model_attribute_groups/_all_docs

我正在尝试编写curl命令以从其他Linux服务器运行JSON Mango查询。

我在文件中有我的芒果查询:" mangoReqPay" ls -l告诉我的是221个字符。

{  "selector": {"status":"stable", "model":"PC-20",  "variant":{    "$in": ["15",  "30"]    }  },  "fields":["_id","_rev","status",  "model","variant","variant-type",  "oem","historicaloem","displaymodel",  "sactmodel"]}

这是我尝试使用的命令。

curl -H "Content-Type: application/json" \
 -H "Content-Length: 221" \
 -X POST \
 -d mangoReqPay \
 -H "Host: http://my.server.com:5984/model_attribute_groups\_find"

当我提交此命令时,我没有得到任何响应,它只是坐在那里等待更多输入。

有人可以给我一个正确方向的推动吗?

由于

1 个答案:

答案 0 :(得分:1)

您尚未指定网址。您的主机名在" -H"参数不是你想让curl请求的网址 - 它只是设置标题。

当我运行命令时,我得到了错误(这是正确的):

#include <iostream>
#include <vector>

struct unspecified
{
};

template<class TYPE>
class TwoDee{
    int rows;
    int cols;
    std::vector<TYPE> data;
public:
    TwoDee(int row, int col):rows(row), cols(col), data(rows*cols)
    {
        // does nothing. All of the heavy lifting was in the initializer
    }
    // std::vector eliminates the need for destructor, assignment operators, and copy
    //and move constructors. All hail the Rule of Zero!
    //add a convenience method for easy access to the vector
    TYPE & operator()(size_t row, size_t col)
    {
        return data[row*cols+col];
    }
    TYPE operator()(size_t row, size_t col) const
    {
        return data[row*cols+col];
    }
};

void function(TwoDee<unspecified *> & matrix)
{
    // does stuff to matrix
}

int main()
{
    TwoDee<unspecified *> test(10,10);
    function(test);
}

只需指定您希望curl在末尾(或开头)没有任何标记即可获取的URL。

此外,您不需要&#34;内容长度:221&#34;。如果您希望它从文件中读取,请使用&#39; @&#39;

启动文件名
相关问题