c++ - 使用适用于 C++ 的 Google API 客户端库的 HTTP 请求

标签 c++ http google-api google-api-client

我正在尝试使用适用于 C++ 的 Google API 客户端库发送 HTTP GET 请求,使用 http://google.github.io/google-api-cpp-client/latest/guide/making_http_requests.html 中提到的用例示例.

这是我的程序:

#include "googleapis/client/data/data_reader.h"
#include "googleapis/client/transport/http_request.h"
#include "googleapis/client/transport/http_response.h"
#include "googleapis/client/transport/http_transport.h"
#include "googleapis/client/transport/curl_http_transport.h"
#include "googleapis/base/scoped_ptr.h"
#include "googleapis/base/mutex.h"
#include <curl/curl.h>
#include <glog/logging.h>
#include "googleapis/util/status.h"
#include <iostream>
#include <cstring>
#include <cstdlib>

using namespace googleapis;
using namespace std;

using googleapis::client::HttpRequest;
using googleapis::client::HttpRequestState;
using googleapis::client::HttpResponse;
using googleapis::client::HttpTransport;
using googleapis::client::HttpTransportLayerConf;
using googleapis::client::HttpTransportOptions;

void IllustrateGet(const char* url, HttpTransport* transport) {
    scoped_ptr<HttpRequest> request(
            transport->NewHttpRequest(HttpRequest::GET));
    request->set_url(url);
    util::Status status = request->Execute();
    if (!status.ok())
        cerr << status.error_message();
}


int main(){

    string url = "http://www.google.com/cloudprint";
    scoped_ptr<HttpTransport> transport;

    IllustrateGet(url, transport);
    return 0;

}

在 main() 中,当我尝试调用 IllustrateGet 函数时,出现无效参数异常。有人可以帮助我了解 HttpTransport 为发送 HTTP GET 请求做了什么吗?

最佳答案

调用 IllustrateGet(url.c_str(), transport);

关于c++ - 使用适用于 C++ 的 Google API 客户端库的 HTTP 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29568514/

相关文章:

c++ - 在 Qt 的对话窗口中隐藏主窗口后如何显示主窗口

c++ - 为什么这个输出十六进制而不是一个句子?连接器/C++

c++ - 拖拽后获取QTableView的实际行号

python - HTTP 状态代码 200 与 202

python - 如何在Google Drive中搜索特定文件?

c++ uint8 缓冲区数组

javascript - 在 AJAX 中仅检索远程 URL 的一部分

security - 为什么 Amazon Web Services 的登录页面 URL 很长

google-api - 在 Google 日历事件上触发脚本

php - 运费取决于卖家和客户之间的距离