Publish data using libcurl

I have a problem with libcurl. I wrote a simple program that should publish data (fill out a form), but the program does not work. My form:

... <div><label for="id_person_name">Your name</label> <input type="text" id="id_person_name" name="name" /></div> <div></div> <div class="clear"></div> <div><label for="id_comment">Comment</label><textarea name="comment" id="id_comment" rows="10" cols="60" class="txt"></textarea></div> ... 

Program:

 #include <curl/curl.h> #include <iostream> using namespace std; int main(){ CURL *curl; CURLcode res; curl = curl_easy_init(); if(curl) { curl_easy_setopt(curl, CURLOPT_URL, "http://examplesite.com"); curl_easy_setopt(curl, CURLOPT_POST, 1); curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "name=Bjarne&comment=example"); res = curl_easy_perform(curl); curl_easy_cleanup(curl); cout << endl; } return 0; } 

Of course, I tested this code: http://curl.haxx.se/libcurl/c/postit2.html , but it does not work.

Can anybody help me?

+6
source share
1 answer

you need to set CURLOPT_URL to address points, check

http://curl.haxx.se/libcurl/c/http-post.html

eg

+3
source

Source: https://habr.com/ru/post/921069/


All Articles