![](/img/trans.png)
[英]Google API Client Library for C++ vs libcurl for sending HTTP request?
[英]HTTP Request using Google API Client Library for C++
我正在嘗試使用Google API客戶端庫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請求會做什么嗎?
調用IllustrateGet(url.c_str(),transport);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.