i trying use libcurl c api post thing on site. url works when access browser. copied same browser bar , accessing in program. program hangs in curl_easy_perform call , never returns. provide write_callback never gets invoked. whats wrong piece of code below
for privacy reasons removed url piece of code below .
int main(void) { curlcode res; curl *curl = curl_easy_init(); if(curl) { curl_easy_setopt(curl, curlopt_url, ""); curl_easy_setopt(curl, curlopt_post, 1); //curl_easy_setopt(curl, curlopt_connecttimeout, 1l ); //curl_easy_setopt(curl, curlopt_timeout, 1l ); curl_easy_setopt(curl, curlopt_writefunction, write_callback); res = curl_easy_perform(curl); if (res != curle_ok) fprintf(stderr,"failed: %s", curl_easy_strerror(res)); curl_easy_cleanup(curl); } return -1; }
you need set curlopt_postfields
, curlopt_postfieldsize
well.
so if post looks http://awesome.com/superpost.html?blah=hi
- url should be: http://awesome.com/superpost.html
- postfields should be: blah=hi
- curlopt_postfieldsize should be: strlen("blah=hi")
there decent examples on curl site:
- basic post: http://curl.haxx.se/libcurl/c/simplepost.html
- more elaborate: http://curl.haxx.se/libcurl/c/postit2.html
note: you'll want escape post field key/values curl_escape
Comments
Post a Comment