【问题标题】:HTTP Request using Google API Client Library for C++使用适用于 C++ 的 Google API 客户端库的 HTTP 请求
【发布时间】:2015-04-10 18:38:30
【问题描述】:

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

这是我的程序:

#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 请求的吗?

【问题讨论】:

  • 您知道如何在没有 scoped_ptr 的情况下更改您的代码 sn-p 吗?我现在下载了库,但找不到包含相关文件的方法,即 - googleapis/base/scoped_ptr.h"

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


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-09-27
    • 1970-01-01
    • 1970-01-01
    • 2022-08-16
    • 2012-08-15
    • 2015-07-02
    • 1970-01-01
    相关资源
    最近更新 更多