码迷,mamicode.com
首页 > 移动开发 > 详细

HockeyApp 自己上传错误日志的坑

时间:2019-04-06 00:28:39      阅读:195      评论:0      收藏:0      [点我收藏+]

标签:led   last   形式   this   set   thread   ror   lis   ini   

0 HockeyApp对于上传格式有严格要求,只要不符合规定,不好意思,没有错误信息,只有404。如果是404,可以考虑其实是格式错误。

1 HockeyApp只接受multipart上传,可以使用curl的form post。也可以使用mine,具体查看文档。

2 log,description,attachment0这三个字段必须以文件形式上传,也就是说,字段头中必须有filename="xxxx",否则404

 

附带自己写的c++用curl上传的线程函数范例,经测试可用:

struct SendErrorReportThreadData
{
    ErrorReport data;
    std::string url;
    std::string content;
};void SendErrorReportThread(SendErrorReportThreadData* data)
{
    CURL *curl;
    CURLcode res;
    struct curl_httppost *formpost = NULL;
    struct curl_httppost *lastptr = NULL;
    struct curl_slist *headerlist = NULL;
    static const char buf[] = "Expect:";
    curl = curl_easy_init();
    if(curl) {
        curl_formadd(&formpost,
                     &lastptr,
                     CURLFORM_COPYNAME, "log",
                     CURLFORM_BUFFER, "log.txt",
                     CURLFORM_BUFFERPTR, data->content.c_str(),
                     CURLFORM_BUFFERLENGTH, data->content.size(),
                     CURLFORM_END);
        
        if(!data->data.message.empty())
        {
            curl_formadd(&formpost,
                         &lastptr,
                         CURLFORM_COPYNAME, "description",
                         CURLFORM_BUFFER, "description.txt",
                         CURLFORM_BUFFERPTR, data->data.message.c_str(),
                         CURLFORM_BUFFERLENGTH, data->data.message.size(),
                         CURLFORM_END);
        }
        
        if(!data->data.log.empty())
        {
            curl_formadd(&formpost,
                         &lastptr,
                         CURLFORM_COPYNAME, "attachment0",
                         CURLFORM_BUFFER, "attachment0.txt",
                         CURLFORM_BUFFERPTR, data->data.log.c_str(),
                         CURLFORM_BUFFERLENGTH, data->data.log.size(),
                         CURLFORM_END);
        }
        headerlist = curl_slist_append(headerlist, buf);
        curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headerlist);
        /* what URL that receives this POST */
        curl_easy_setopt(curl, CURLOPT_URL, data->url.c_str());
        curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost);
        //curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
        curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0);
        
        curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0);
        res = curl_easy_perform(curl);
        /* Check for errors */
        if(res != CURLE_OK)
        {
            CCLOG("OSUtility::SendErrorReport ----> curl_easy_perform() failed: %s\n",
                  curl_easy_strerror(res));
        }
        else
        {
            long http_code = 0;
            curl_easy_getinfo (curl, CURLINFO_RESPONSE_CODE, &http_code);
            CCLOG("OSUtility::SendErrorReport ----> successfully send one report. HTTP code:%ld", http_code);
        }
        /* always cleanup */
        curl_easy_cleanup(curl);
        
        /* then cleanup the formpost chain */
        curl_formfree(formpost);
        /* free slist */
        curl_slist_free_all(headerlist);
    }
    delete data;
}

 

HockeyApp 自己上传错误日志的坑

标签:led   last   形式   this   set   thread   ror   lis   ini   

原文地址:https://www.cnblogs.com/eaglelun/p/HockeyApp.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!