Search code examples
jsonhttptizentizen-wearable-sdktizen-native-app

How to sendi HTTP request and parse JSON response in TIZEN watch using Native?


Hi I'am new to Tizen Development and would like to explore functions/features like what I used in android development. So I want to learn how to post/get HTTP and parse the json response from the URL using Native Tizen watch. Can anyone help me or point me to some tutorials?


Solution

  • You can do this using curl . Here is an example using:

    Add these headers

    #include <curl/curl.h>
    #include <net_connection.h>
    

    And implement like this

        /* Initialize CURL */ 
        CURL *curlHandler = curl_easy_init();
    
    
        connection_h connection;
    
        int conn_err;
        conn_err = connection_create(&connection);
        if (conn_err != CONNECTION_ERROR_NONE) {
            /* Error handling */
            return false;
        }
    
        if(curlHandler) {
          /* Set CURL parameters */
          curl_easy_setopt(curlHandler, CURLOPT_URL, "http://api.yoururl.com");
          curl_easy_setopt(curlHandler, CURLOPT_CUSTOMREQUEST, "POST");
          curl_easy_setopt(curlHandler, CURLOPT_POSTFIELDS,  jObj);
    
          /* Perform the request */ 
          CURLcode res = curl_easy_perform(curlHandler);
    
          /* Check for errors */ 
          if(res != CURLE_OK)
            fprintf(stderr, "CURL failed: %s\n",
                    curl_easy_strerror(res));
    
          /* Clean up */ 
          curl_easy_cleanup(curlHandler);
          json_object_object_del(jObj, "name");
          connection_destroy(connection);
          free(jObj);
      }
    

    You can also check this link and this link.

    Tutorial: This