HTTP 请求使用 Google API 客户端库进行C++



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

这是我的程序:

#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请求而做什么吗?

Call IllustrateGet(url.c_str), transport);

相关内容

  • 没有找到相关文章

最新更新