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

3
我正在尝试使用Google API Client Library for C++发送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请求的吗?

你知道如何修改你的代码片段,使其不使用scoped_ptr就能正常工作吗?我现在已经下载了这个库,但是找不到相关文件的包含方式,例如:googleapis/base/scoped_ptr.h"。 - Guy Avraham
1个回答

1

调用 IllustrateGet(url.c_str(), transport) 方法。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接