GithubHelp home page GithubHelp logo

curlcpp's Introduction

curlcpp

An object-oriented C++ wrapper for cURL tool. I'm working for you. :P

There are a bunch of cURL C++ wrappers out there, but I personally don't like any of them. So, I was writing a framework for my university and I needed a curl wrapper in C++, so I wrote it. I'm still working on it, so, if you find bugs or errors, please tell me! :)

If you want to know a bit more about cURL, you should go on the official website and read about the three interfaces that curl implements: http://curl.haxx.se/

Compile and link

Standalone

cd build
cmake ..
make # -j2

Then add <curlcpp root>/build/src/ to your library path and <curlcpp root>/include/ to your include path.

When linking, link against curlcpp (e.g.: gcc example.cpp -o example -lcurlcpp).

Submodule

When using a git submodule and CMake-buildsystem, add the following lines to your CMakeLists.txt:

ADD_SUBDIRECTORY(ext/curlcpp) # Change `ext/curlcpp` to a directory according to your setup
INCLUDE_DIRECTORIES(${CURLCPP_SOURCE_DIR}/include)

Simple usage example

Here's an example of a simple HTTP request to get google web page, using the curl_easy interface:

#include "../include/curl_easy.h"
// only "CurlEasy.h" if you use above submodule-way of compilation and linking

using curl::CurlEasy;

int main(int argc, const char **argv) {
    CurlEasy easy;
    easy.addOption(CurlPair<CURLoption,string>(CURLOPT_URL,"http://www.google.it") );
    easy.addOption(CurlPair<CURLoption,long>(CURLOPT_FOLLOWLOCATION,1L) );
    easy.perform();
    return 0;
}

Here's instead, the creation of an HTTPS POST login form:

#include "CurlEasy.h"
#include "CurlHttpPost.h"
// only "CurlEasy.h" and "CurlHttpPost.h" if you use above submodule-way of compilation and linking

using curl::CurlEasy;
using curl::CurlHttpPost;

int main(int argc, const char * argv[]) {
    CurlEasy easy;
    CurlHttpPost post;
    post.formAdd(CurlPair<CURLformoption,string>(CURLFORM_COPYNAME,"user"),CurlPair<CURLformoption,string>(CURLFORM_COPYCONTENTS,"username"));
    post.formAdd(CurlPair<CURLformoption,string>(CURLFORM_COPYNAME,"passw"),CurlPair<CURLformoption,string>(CURLFORM_COPYCONTENTS,"password"));
    easy.addOption(CurlPair<CURLoption,string>(CURLOPT_URL,"https://xxxxx/"));
    easy.addOption(CurlPair<CURLoption,CurlHttpPost>(CURLOPT_HTTPPOST,post));
    easy.perform();
    return 0;
}

That's it! :)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.