通过libcurl在dropbox上创建文件夹时出错

error when creating folder on dropbox via libcurl

本文关键字:文件夹 出错 创建 libcurl dropbox 通过      更新时间:2023-10-16

我正在尝试制作一个使用Dropbox的c++应用程序。当我试图创建一个新文件夹时,我会出现以下错误:{"error":"Not Found"}和"HTTP/1.1 404 Not Found(HTTP/1.1 404Not Found)"。

我遵循了Dropbox的RESTApi的说明,所以我使用了POST方法。(我不确定是否可以使用PUT)。

这是我的代码:

void createDirectory(const char *new_Directory_Path)

{string create_Directory_Url="https://api.dropbox.com/1/fileops/create_folder/sandbox/test_folder";

    CURL* curl = curl_easy_init();
    if(!curl)
    {
        CURLcode res;
        struct curl_slist *headers = NULL;
        string my_header = "Authorization: OAuth oauth_version="1.0", oauth_signature_method="PLAINTEXT", 
        oauth_consumer_key=""
                    + m_consumer_key + "", oauth_token="" + m_accessKey + "", oauth_signature=""
                    + m_consumer_secret + "&" + m_accessSecret + """;
        headers = curl_slist_append(headers, my_header.c_str());
        curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
        curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
        curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
        curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
        curl_easy_setopt(curl, CURLOPT_POST, 1L);
        curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0);
        curl_easy_setopt(curl, CURLOPT_URL, create_Directory_Url.c_str());
        res = curl_easy_perform(curl);
        curl_slist_free_all(headers);
        curl_easy_cleanup(curl);
    }

}

拜托,有人知道我做错了什么吗?

查看文档,我认为您希望将sandbox/test_folder从url中删除,并使用root=sandbox&path=test_folder作为表单值。

以下是提交表单参数的示例:http://curl.haxx.se/libcurl/c/postit2.html

编辑:我在这里找到了另一个例子:https://github.com/geersch/DropboxRESTApi/blob/master/src/part-3/README.md它似乎显示了添加到url的查询字符串中的参数,而不是表单值。文档页面不清晰。它只是将它们显示为参数,但没有指定哪种类型。