我正在尝试使用Google API Client Library for C++发送HTTP GET请求,使用的是http://google.github.io/google-api-cpp-client/latest/guide/making_http_requests.html中提到的用例示例。
这是我的程序:
在main()函数中,当我尝试调用IllustrateGet函数时,会出现无效参数异常。有人可以帮我理解HttpTransport是如何发送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请求的吗?