Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions src/helloworld.cpp
Original file line number Diff line number Diff line change
@@ -1,24 +1,35 @@
#include<iostream>
#include<curl/curl.h>

#include <iostream>
#include <curl/curl.h>
#include <string>


static size_t WriteCallback(void *contents, size_t size, size_t nmemb, void *userp){
((std::string*)userp)->append((char*)contents, size * nmemb);
return size * nmemb;
}

int main(int argc, char *argv[]) {

std::cout << "Hello World!" << std::endl;

CURL* curl;
CURLcode res;
std::string readBuffer;

curl = curl_easy_init();

const char *data = "foo=bar";
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer);

res = curl_easy_perform(curl);
if(res == CURLE_OK) {
long response_code;
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &response_code);
std::cout << "Got response code: " << response_code << std::endl;
std::cout << "Content " << readBuffer << std::endl;
}

curl_easy_cleanup(curl);
Expand Down