dev: optimize http post

This commit is contained in:
wwhai
2025-02-16 19:48:11 +08:00
parent c570005cb6
commit 2594473640
2 changed files with 7 additions and 7 deletions
+1 -1
View File
@@ -22,5 +22,5 @@
// 回调函数,用于处理响应数据
size_t write_callback(void *contents, size_t size, size_t nmemb, void *userp);
// 打印表示识别类型的 JSON 字符串的函数,增加时间戳和上传者 UUID
void post_recognized_type(const char *url, int type, const char *device_uuid);
void post_recognized_type(const char *url, const char *type, const char *device_uuid);
#endif
+6 -6
View File
@@ -20,10 +20,10 @@
size_t write_callback(void *contents, size_t size, size_t nmemb, void *userp)
{
size_t realsize = size * nmemb;
log_info( "=== http write callback === %.*s", (int)realsize, (char *)contents);
log_info("=== http write callback === %.*s", (int)realsize, (char *)contents);
return realsize;
}
void post_recognized_type(const char *url, int type, const char *device_uuid)
void post_recognized_type(const char *url, const char *type, const char *device_uuid)
{
char json_body[256];
time_t now = time(NULL);
@@ -31,8 +31,8 @@ void post_recognized_type(const char *url, int type, const char *device_uuid)
char ts[20];
tm_info = localtime(&now);
strftime(ts, sizeof(ts), "%Y-%m-%d %H:%M:%S", tm_info);
snprintf(json_body, sizeof(json_body), "{\"type\": %d, \"ts\": \"%s\", \"device_uuid\": \"%s\"}", type, ts, device_uuid);
log_info( "====== post_recognized_type json_body ======");
log_info( "POST: %s, Body: %s", url, json_body);
log_info( "============================================");
snprintf(json_body, sizeof(json_body), "{\"type\": %s, \"ts\": \"%s\", \"device_uuid\": \"%s\"}", type, ts, device_uuid);
log_info("====== post_recognized_type json_body ======");
log_info("POST: %s, Body: %s", url, json_body);
log_info("============================================");
}