Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTTP Request using Google API Client Library for C++

I am trying to send an HTTP GET Request using Google API Client Library for C++ using the use case examples mentioned at http://google.github.io/google-api-cpp-client/latest/guide/making_http_requests.html.

Here's my program:

#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;

}

In main(), when I try to invoke the IllustrateGet function, I get an invalid argument exception. Could some one help me understand what does HttpTransport do in order to send an HTTP GET Request?

like image 977
ap6491 Avatar asked Mar 23 '26 17:03

ap6491


1 Answers

Call IllustrateGet(url.c_str(), transport);

like image 78
ND003 Avatar answered Mar 26 '26 08:03

ND003



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!