[English README] [中文说明]
CXXUrl is base on libcurl, but it's not only an object-oriented C++ wrapper for cURL.
Now, CXXUrl is header-only!
By the way, if you want to known more about libcurl, you should go http://curl.haxx.se/
Under MIT LICENSE
author: xiaozhuai - xiaozhuai7@gmail.com
Build examples and tests with cmake
$ cd /path/to/cxxurl
$ mkdir build
$ cd build
$ cmake ..
$ make
$ make check # run test case
Once you have build the project, you can run some examples.
$ ../example_server/start_server # Run a http server for examples, require php > 5.6
$ ./example_get
Just drop files in src/cxxurl
to where you like!
You can find all example source in example dir.
That's all you need to perform a get request.
And you can parse body, we provide a json parser.
See examples/example_parse_json_body.cpp
Thank https://github.com/nlohmann/json, a modern json parser for c++.
You can simplely download a file just change the contentOutput
to a ofstream
instance.
See examples/example_download.cpp
And if you need header output, just set it
See examples/example_response_header.cpp
Of course, we also provide a parser
See examples/example_parse_response_header.cpp
Do a post request maybe something more than get request, but it's still easy
CXXUrl provide three form type, SimpleForm
, MultipartForm
and RawRequestBody
.
See examples/example_get_https_enable.cpp
And you can disable ssl verify on a https website by .verifySSL(false)
See examples/example_get_https_disable.cpp
Headers usage look like post form
See examples/example_set_request_header.cpp
Some frequently used headers, such as userAgent and referer, you can simplely set by .userAgent(...)
, .referer(...)
Let's talk about cookies.
First, we need export cookies to a file when login some website, and then import it if we need visit it after.
See examples/example_cookie.cpp
Yes, if you want to use plain CURL api, here CXXurl provide a method.
See examples/example_use_curl_option.cpp
This example is just the same with simple get example.
The deference is use .curlOptionString(CURLOPT_URL, "http://xiaozhuai.github.io")
to take place of .url("http://xiaozhuai.github.io")
This just a builder to simplify code. Yes, you can use CXXurl without builder, it's just fine.
See examples/example_without_request_builder.cpp
So, which one do you prefer?
Thank cURL
Вы можете оставить комментарий после Вход в систему
Неприемлемый контент может быть отображен здесь и не будет показан на странице. Вы можете проверить и изменить его с помощью соответствующей функции редактирования.
Если вы подтверждаете, что содержание не содержит непристойной лексики/перенаправления на рекламу/насилия/вульгарной порнографии/нарушений/пиратства/ложного/незначительного или незаконного контента, связанного с национальными законами и предписаниями, вы можете нажать «Отправить» для подачи апелляции, и мы обработаем ее как можно скорее.
Опубликовать ( 0 )