libcurl2を使用して簡単なhttp getリクエストを作成するクラスを作成しています。私は、C++にかなり新しいですまだ学んが、私はそれがアクセス修飾子または私は誰かがすることを願ってスコープLibcurlエラー受信したデータをディスク/アプリケーションに書き込めませんでした。
とは何かを持って推測している
Libcurl error Failed writing received data to disk/application
: は、私は戻って次のエラーを取得しますこれで私を助けてください。
クラスのHttpConnection
#include "HTTPconnection.h"
#include <iostream>
#include <string>
using namespace httptest;
HTTPconnection::HTTPconnection()
{
curl_global_init(CURL_GLOBAL_DEFAULT);
curl = curl_easy_init();
}
size_t HTTPconnection::write_callback(char * data, size_t
size, size_t nmemb, std::string * writerData)
{
if (writerData == NULL)
return 0;
writerData->append(data, size*nmemb);
return size * nmemb;
}
std::string HTTPconnection::createConnection(const char *url, const char *proxy)
{
curl_easy_setopt(HTTPconnection::curl, CURLOPT_URL, url);
curl_easy_setopt(HTTPconnection::curl, CURLOPT_WRITEFUNCTION, &HTTPconnection::write_callback);
curl_easy_setopt(HTTPconnection::curl, CURLOPT_WRITEDATA, &HTTPconnection::buffer);
res = curl_easy_perform(HTTPconnection::curl);
std::cout << curl_easy_strerror(res);
return buffer;
}
HTTPconnection::~HTTPconnection()
{
curl_easy_cleanup(curl);
curl_global_cleanup();
}
HTTPconnection.h
#ifndef HTTPconnection_H
#define HTTPconnection_H
#include <string>
#include "libcurl/include/curl/curl.h"
#ifdef _DEBUG
#pragma comment(lib, "libcurl/lib/libcurl_a_debug.lib")
#else
#pragma comment(lib, "libcurl/lib/libcurl_a.lib")
#endif
namespace httptest
{
class HTTPconnection
{
public:
//Default Constructor
HTTPconnection();
std::string createConnection(const char *url, const char *proxy);
//Destructor
~HTTPconnection();
private:
//methods
size_t write_callback(char *data, size_t size, size_t nmemb, std::string *writerData);
//members
std::string buffer;
CURL *curl;
CURLcode res;
};
}
#endif // !HTTPconnection_H