问题描述
我正在做C应用程序,使用libcurl将json数据发布到云中。但是我收到错误代码curl_easy_perform 43。
我的代码如下:
int httpconnection (char *Json_Data)
{
int rc = 0;
char Url[180];
CURL *curl;
struct curl_slist *headers = NULL;
strcpy (Url,"https://");
strcat (Url,Host_Name);
strcat (Url,"/devices/");
strcat (Url,ID);
strcat (Url,"/messages/events");
strcat (Url,"?api-version=2016-02-03");
printf ("\n\n URL = %s\n",Url);
headers = curl_slist_append (headers,"Accept: application/json");
headers = curl_slist_append (headers,"Content-Type: application/json");
headers = curl_slist_append (headers,"Username: poc-iotconnect-iothub-eu.azure-devices.net/98f5b52a59aa4503999894c10bc33dca-Demo123/?api-version=2018-06-30");
headers = curl_slist_append (headers,"Authorization : sas");
rc = curl_easy_setopt (curl,CURLOPT_URL,Url);
printf ("\n curl_easy_setopt 1 %d -\n",rc);
rc = curl_easy_setopt (curl,CURLOPT_HTTPHEADER,headers);
printf("\n curl_easy_setopt 2 %d -\n",rc);
rc = curl_easy_setopt (curl,CURLOPT_POSTFIELDS,Json_Data);
printf ("\n curl_easy_setopt 3 %d -\n",rc);
rc = curl_easy_perform(curl);
printf("\n Curl_easy_perform %d -\n",rc);
curl_slist_free_all (headers);
return rc;
}
int main (void)
{
int rc = 0,count = 0;
rc = cloud_init ();
if (rc != 0)
printf ("\n Cloud_init Failed.\n");
Json_Data = Sensor_Data();
rc = httpconnection(Json_Data);
if (rc != 0)
printf ("\n\n HTTP Connection Failed.. \n ");
return ;
}
输出:
URL = https://poc-iotconnect-iothub-eu.azure-devices.net/devices/98f5b52a59aa4503999894c10bc33dca-Demo123/messages/events?api-version=2016-02-03
curl_easy_setopt 1 43 -
curl_easy_setopt 2 43 -
curl_easy_setopt 3 43 -
Curl_easy_perform 43 -
HTTP Connection Failed..
预先感谢
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)