0

こんにちは、私はTizen SDKと時計アプリケーションを開発するのが初めてです。投稿/取得にカールを使用しているときにエラーが発生しました。以下は私が使用しているコードです、誰も助けることができますか?Tizenウェアラブルネイティブアプリケーションでcurlを使用してホスト名エラーを解決しないでください

CURL *curl; 
CURLcode res; 

dlog_print(DLOG_DEBUG, TAG, "curl start"); 

/* In windows, this will init the winsock stuff */ 
curl_global_init(CURL_GLOBAL_ALL); 

/* get a curl handle */ 
curl = curl_easy_init(); 

if(curl) { 
    dlog_print(DLOG_DEBUG, TAG, "curl init"); 
    /* Set CURL parameters */ 
    /* First set the URL that is about to receive our POST. This URL can 
    just as well be a https:// URL if that is what should receive the 
    data. */ 
    curl_easy_setopt(curl, CURLOPT_URL, "http://google.com"); 
    /* Now specify the POST data */ 
    //curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "w=4&project=curl"); 

    /* Perform the request, res will get the return code */ 
    res = curl_easy_perform(curl); 
    /* Check for errors */ 
    if(res != CURLE_OK) 
     dlog_print(DLOG_DEBUG, TAG, "curl_easy_perform() Failed: %s\n",curl_easy_strerror(res)); 
    else{ 
     dlog_print(DLOG_DEBUG, TAG, "curl_easy_perform() Success"); 

    } 

    /* always cleanup */ 
    curl_easy_cleanup(curl); 
    } 
else{ 
    dlog_print(DLOG_DEBUG, TAG, "curl failed"); 
} 
     curl_global_cleanup(); 

EDIT: エラーは、API権限で、このようなコードを試すことが

答えて

1

「ホスト名を解決できません」です。

<privilege>http://tizen.org/privilege/network.get</privilege> 
    <privilege>http://tizen.org/privilege/internet</privilege> 

このコードは、単にデータのために要求し、受け取りますそのデータ。ここでは

dlog_print(DLOG_INFO, "data", "Response Data"); 
dlog_print(DLOG_INFO, "data", chunk.memory); 

を使用して受信データを表示します。

Eina_Bool sendRequest(void *data EINA_UNUSED) { 
CURL *curl; 
CURLcode curl_err; 
chunk.memory = malloc(1); 
chunk.size = 0; 
curl = curl_easy_init(); 
connection_h connection; 
int conn_err; 
conn_err = connection_create(&connection); 
if (conn_err != CONNECTION_ERROR_NONE) { 
    /* Error handling */ 
    return false; 
} 
curl_easy_setopt(curl, CURLOPT_URL, 
     "http://apidev.accuweather.com/currentconditions/v1/28143.json?language=en&apikey=hoArfRosT1215"); 
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteMemoryCallback); 
/* we pass our 'chunk' struct to the callback function */ 
curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&chunk); 
curl_err = curl_easy_perform(curl); 
if (curl_err != CURLE_OK) { 
    /* Error handling */ 
    return false; 
} 
dlog_print(DLOG_INFO, "data", "Response Data"); 
dlog_print(DLOG_INFO, "data", chunk.memory); 
curl_easy_cleanup(curl); 
free(chunk.memory); 
connection_destroy(connection); 
return EINA_TRUE;} 

ログ出力:関数呼び出し

enter image description here

はそれがあなたのために働くことを願っています。

+0

ちょうどパラメータ*データは何ですか? – BradlyMan

+0

私には権限がないようです。私は機能を追加するだけで十分だと思った。ありがとうございました。ありがとうございました! – BradlyMan

関連する問題