我正在尝试使用Dropbox API获取Dropbox中某个文件的一些元数据信息。
这是我的邮政编码
std::ostringstream stream;
curl_slist* headers = NULL;
CURL* curl = curl_easy_init();
char data[50];
snprintf(data, sizeof(data), "{\"path\":\"%s\"}", "/3.png");
curl_easy_setopt(curl, CURLOPT_URL, "https://api.dropboxapi.com/2/files/get_metadata");
headers = curl_slist_append(headers, "Authorization: <MY TOKEN>");
headers = curl_slist_append(headers, "\"Content-Type\":\"application/json\"");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
curl_easy_setopt(curl, CURLOPT_POST, 1);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &stream);
/* size of the POST data */
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, 30L);
/* pass in a pointer to the data - libcurl will not copy */
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, R"({"path":"/3.png"})"); //Tried data char array it doesn't work too.
CURLcode res = curl_easy_perform(curl);
if (res != CURLE_OK)
return 0;
/* convert stream to string format */
std::string output = stream.str();
curl_easy_cleanup(curl);
返回HTTP 400代码
这是我在使用curllib进行http post后得到的错误
<!DOCTYPE html>
<html>
<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Dropbox</title>
<link href="https://cfl.dropboxstatic.com/static/metaserver/static/css/error.css" rel="stylesheet" type="text/css"/>
<link rel="shortcut icon" href="https://cfl.dropboxstatic.com/static/metaserver/static/images/favicon.ico"/>
</head>
<body>
<div class="figure">
<img src="https://cfl.dropboxstatic.com/static/metaserver/static/images/illustration_catalog/sickbox-illo_m1.png" srcset="https://cfl.dropboxstatic.com/static/metaserver/static/images/illustration_catalog/sickbox-illo_m1@2x.png 2x" alt="Error: 5xx"/>
</div>
<div id="errorbox">
<h1>Error</h1>Something went wrong. Don't worry, your files are still safe and the Dropboxers have been notified. Check out our <a href="https://www.dropbox.com/help">Help Center</a> and <a href="https://forums.dropbox.com">forums</a> for help, or head back to <a href="https://www.dropbox.com/home">home</a>.
</div>
在Postman上它给出了很好的响应,但在我的C++代码中它给了我错误,正如你在上面看到的
Http Web请求主体应该如下所示
{
"path": "/3.png"
}
这是我从 Postman 那里得到的回应
{
".tag": "file",
"name": "3.png",
"path_lower": "/3.png",
"path_display": "/3.png",
"id": "id:kVJQZOYYiMsAAAAAAAAABg",
"client_modified": "2023-02-01T18:54:24Z",
"server_modified": "2023-02-01T18:54:24Z",
"rev": "015f3a7fa16a9c100000002912dfcc0",
"size": 5160,
"is_downloadable": true,
"content_hash": "feb3516ea07bab6053eecc7367ee9c282846f7bc17751b2819b85aa0f3ddefb5"
}
1条答案
按热度按时间2exbekwf1#
此行:
看起来可疑与所有的内联引号围绕它。
它不应该只是:
您应该使用Fiddler、Charles或类似的HTTP捕获代理工具,将应用程序发送的请求/响应与Postman发送的请求/响应进行比较。我认为,如果上述方法不能解决问题,您将看到一两个差异。