HttpPost using libCurl

HttpPost using libCurl

BY 23 Mar 2015 Native Application Development

Hi,

I’m trying to use libcurl api’s to post data to server (HttpPost).

Tried with this sample code :

      CURL *curl;
      CURLcode res;   

      curl_global_init(CURL_GLOBAL_ALL);
      curl = curl_easy_init();
      curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
      curl_easy_setopt(curl, CURLOPT_URL, “http://www.example.com/hello-world”);
      curl_easy_setopt(curl, CURLOPT_POST, 1);
      curl_easy_setopt(curl, CURLOPT_POSTFIELDS, “foo=bar&foz=baz”);
      res = curl_easy_perform(curl);
      curl_easy_cleanup(curl);

Problems:

1. res = CURLE_COULDNT_RESOLVE_HOST always

2. Also “curl_easy_perform” takes very long time to perform the request – nearly 1 minute!

Kindly help me solving the issues.

 

Thanks,

Sathya Priya


 

Written by