언어 설정

Menu
Sites
Language
HttpPost using libCurl

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


 

답변 바로가기

Responses

6 댓글
Alex Ashirov

Hi,

You can also try to send libcurl related questions in their mailing list:

http://curl.haxx.se/mail/list.cgi?list=curl-library

Hopefully, they will be able to answer the questions quickly.

colin Rao

seems it is the curl can't find the host of you web app, in other words it's can't get the ip address from the DNS server by the domain name www.example.com/

try more, make sure that you can open the link in explorer http://www.example.com/hello-world

ping www.example.com in command, get it's ip address, and use the ip address to replace www.example.com in your source code.

Alex Ashirov

Hi,

I have tried the code snippet above and I received the same error code. I tried on the both Emulator and Z1 device. Results were the same. I also, tried HHTP Post sample downloaded from the Libcurl site with the same result. I tried different URLs. I was able to ping them and I was able to open them in browser, but curl_easy_perform() returned CURLE_COULDNT_RESOLVE_HOST anyway. I am not a curl expert and I can’t say for sure if it’s our mistake or curl doesn’t work correctly.

Sathya Priya R

Thanks Alex!

I shall keep trying.. Was about to post the problem in the curl mail-list that you had shared previously.

Thanks,
Sathya Priya R

 

 

 

Mark as answer
Sathya Priya R

Hi Alex,

Adding "http://tizen.org/privilege/internet" privilge is making it to work and receive CURLE_OK response.

Thanks,

Sathya Priya R

 


 

Alex Ashirov

Hi,

Thank you for sharing this info!

It works for me as well. Indeed, there is some notice about additional privileges in the Tizen help:

https://developer.tizen.org/dev-guide/2.3.0/org.tizen.mobile.native.apireference/group__OPENSRC__CURL__FRAMEWORK.html

but I missed this during my experiments.