Skip to navigation
Put a GET request content into a c string
24.10.19
#include "stdio.h" #include "stdlib.h" #include "curl/curl.h" #include "string.h" size_t static curl_write(void *buffer, size_t size, size_t nmemb, void *userp) { userp += strlen(userp); memcpy(userp, buffer, nmemb); return nmemb; } int get_url() { CURL *curl; CURLcode res; char *s = (char *) malloc(512); curl = curl_easy_init(); if (curl) { curl_easy_setopt(curl, CURLOPT_URL, "https://foo.bar"); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, curl_write); curl_easy_setopt(curl, CURLOPT_WRITEDATA, s); res = curl_easy_perform(curl); curl_easy_cleanup(curl); } printf("GREAT SUCCESS!! Your string is %s\n", s); } int main( int argc, char *argv[] ) { get_url(); return 0; }
https://www.programiz.com/c-programming/c-input-output
Reply
Anonymous
Information Epoch 1732625338
Using text data files.
Home
Notebook
Contact us