Skip to content

Commit 95a2983

Browse files
committed
Update README.md
1 parent e131fb6 commit 95a2983

File tree

1 file changed

+82
-1
lines changed

1 file changed

+82
-1
lines changed

README.md

Lines changed: 82 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,83 @@
11
# curl-cpp-wrapper
2-
Simple libcurl wrapper in C++
2+
3+
A very simple HTTP client (C++ wrapper for curl). Requires libcurl http://curl.haxx.se
4+
If you are using Visual C++ your also have to install msinttypes (headers are provided in "include" directory).
5+
6+
Usage
7+
8+
Do a GET request:
9+
```cpp
10+
NetworkClient nc;
11+
nc.doGet("http://google.com/?q=" + nc.urlEncode("Smelly cat");
12+
std::cout << nc.responseBody();
13+
```
14+
15+
Do a POST request:
16+
```cpp
17+
nc.setUrl("https://www.googleapis.com/oauth2/v3/token");
18+
nc.addQueryParam("refresh_token", refreshToken);
19+
nc.addQueryParam("client_id", clientId);
20+
nc.addQueryParam("client_secret", clientSecret);
21+
nc.addQueryParam("grant_type", "refresh_token");
22+
nc.doPost("");
23+
```
24+
25+
Do a POST request with RAW data:
26+
```cpp
27+
nc.setUrl("https://www.googleapis.com/oauth2/v3/token");
28+
nc.doPost("param1=value&param=value");
29+
```
30+
31+
Downloading a file:
32+
```cpp
33+
NetworkClient nc;
34+
nc.setOutputFile("d:\\image.png"); //only UTF-8 file names are supported on Windows
35+
nc.doGet("http://i.imgur.com/DDf2wbJ.png");
36+
```
37+
38+
Uploading a file:
39+
```cpp
40+
#include "NetworkClient.h"
41+
#include "Core/Utils/CoreUtils.h"
42+
NetworkClient nc;
43+
std::string fileName = "c:\\test\\file.txt"; //only UTF-8 file names are supported on Windows
44+
//std::string fileName = IuCoreUtils::SystemLocaleToUtf8(fileName); <-- if you want to upload a file with ANSI filename on Windows
45+
nc.setUrl("http://takebin.com/action");
46+
nc.addQueryParamFile("file", fileName, IuCoreUtils::ExtractFileName(FileName),"");
47+
nc.addQueryParam("fileDesc", "cool file");
48+
49+
nc.doUploadMultipartData();
50+
if ( nc.responseCode() == 200 ) {
51+
std::cout << nc.responseBody();
52+
}
53+
```
54+
55+
Do a PUT request:
56+
```cpp
57+
nc.setMethod("PUT");
58+
nc.setUrl("https://www.googleapis.com/drive/v2/files/" + id);
59+
nc.addQueryHeader("Authorization", "Basic ");
60+
nc.addQueryHeader("Content-Type", "application/json");
61+
std::string postData = "{\"title\" = \"SmellyCat.jpg\"}";
62+
nc.doUpload("", postData);
63+
```
64+
65+
Uploading a file to FTP:
66+
```cpp
67+
std::string fileName = "c:\\test\\file.txt";
68+
nc.setUrl("ftp://example.com");
69+
nc.setMethod("PUT");
70+
nc.doUpload(fileName, "");
71+
```
72+
73+
Using proxy:
74+
```cpp
75+
nc.setProxy("127.0.0.1", "8888", CURLPROXY_HTTP); // CURLPROXY_HTTP, CURLPROXY_SOCKS4, CURLPROXY_SOCKS4A, CURLPROXY_SOCKS5, CURLPROXY_SOCKS5_HOSTNAME
76+
```
77+
Custom request header:
78+
```
79+
nc.addQueryHeader("User-Agent", "Mozilla/5.0");
80+
```
81+
82+
If you want to use HTTPS, you should compile libcurl with openssl support (you could also use WinSSL on Windows).
83+
If you compile libcurl for windows with OpenSSL support (instead of WinSSL), you should put "curl-ca-bundle.crt" file into your application's directory).

0 commit comments

Comments
 (0)