【发布时间】:2018-03-04 03:44:35
【问题描述】:
我想从 C++ 调用 Microsoft Vision API,我正在使用 cpr library 发出请求。现在我运行以下代码:
#include <iostream>
#include <cpr/cpr.h>
#include <json.hpp>
int main(int argc, char** argv) {
auto response = cpr::Post(
cpr::Url{"https://westcentralus.api.cognitive.microsoft.com/vision/v1.0/analyze"},
cpr::Body{{"url","https://upload.wikimedia.org/wikipedia/commons/thumb/1/12/Broadway_and_Times_Square_by_night.jpg/450px-Broadway_and_Times_Square_by_night.jpg"}},
cpr::Header{{"Ocp-Apim-Subscription-Key", "xxxxxxxx"}}
);
std::cout << response.status_code ;
auto json = nlohmann::json::parse(response.text);
std::cout << json.dump(4) << std::endl;
}
虽然代码是由cmake 运行的,所以make 是成功的。但是当我执行可执行文件时,出现以下错误:
terminate called after throwing an instance of 'std::length_error'
what(): basic_string::_M_create
Aborted (core dumped)
PS:Microsoft Vision API 的文档可以在 here 找到 所以,如果我做错了什么,请告诉我。另外,如果有人知道如何在 QtQuick 应用程序中发送 http 请求,请告诉我
【问题讨论】: