Send string to request bin

Hi, I would like to send a string to requestbin.net
So the user enters text to the string and right after he enters it, it sends to requestbin.
Any ideas?

Thanks
Last edited on
I suggest using libcurl (https://curl.haxx.se/libcurl/) and json11 (https://github.com/dropbox/json11) to help.

For everything else, you will need to use the public requestbin API.
It partly depends on exactly what you mean by "send a string".
It could be as simple as:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <iostream>
#include <string>
#include <curl/curl.h>

const char* const Address {"http://requestbin.net/r/XXXXXXXX"};

void sendRequest(const std::string& str) {
    curl_global_init(CURL_GLOBAL_ALL);
    CURL *curl = curl_easy_init();
    if (curl) {
        curl_easy_setopt(curl, CURLOPT_URL, Address);
        curl_easy_setopt(curl, CURLOPT_POSTFIELDS, str.c_str());
        CURLcode res = curl_easy_perform(curl);
        if (res != CURLE_OK)
            std::cerr << "curl_easy_perform() failed: "
                      << curl_easy_strerror(res) << '\n';
        curl_easy_cleanup(curl);
    }
    curl_global_cleanup();
}

int main() {
    std::string str;
    std::cout << "Enter string: ";
    std::getline(std::cin, str);
    sendRequest(str);
}

It partly depends on exactly what you mean by "send a string".
It could be as simple as:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <iostream>
#include <string>
#include <curl/curl.h>

const char* const Address {"http://requestbin.net/r/XXXXXXXX"};

void sendRequest(const std::string& str) {
    curl_global_init(CURL_GLOBAL_ALL);
    CURL *curl = curl_easy_init();
    if (curl) {
        curl_easy_setopt(curl, CURLOPT_URL, Address);
        curl_easy_setopt(curl, CURLOPT_POSTFIELDS, str.c_str());
        CURLcode res = curl_easy_perform(curl);
        if (res != CURLE_OK)
            std::cerr << "curl_easy_perform() failed: "
                      << curl_easy_strerror(res) << '\n';
        curl_easy_cleanup(curl);
    }
    curl_global_cleanup();
}

int main() {
    std::string str;
    std::cout << "Enter string: ";
    std::getline(std::cin, str);
    sendRequest(str);
}

	

This will work.

Thank you so much
Topic archived. No new replies allowed.