标题内容类型在curl_multi_add_handle和curl_multi_perform之间发生变化

时间:2012-12-10 14:25:53

标签: c++ curl libcurl

我在c ++应用程序中创建了一个带有标题的cURL帖子:

CURL *curl = curl_easy_init();
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());               
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &bufferdata);     
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writerResponse);

struct curl_slist *headers=NULL;
char outputmessage[]="";            

headers = curl_slist_append(headers, "Accept: application/json");
headers = curl_slist_append(headers, "Content-Type: application/json");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers );
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, cJSONstring.c_str());
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, cJSONstring.length());
curl_easy_setopt(curl, CURLOPT_VERBOSE,1);
curl_easy_setopt(curl, CURLOPT_HEADER,1);
curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION, my_trace);

curl_multi_add_handle(m_telemetryCurlm, curl);

我创建了一个调用multi perform的线程:

void ContentManager::processTelemetry()
{
    m_telemetryThreadRunning = true;
    while(m_telemetryThreadRunning)
    {
        static_cast<ADCAnalytics*>(m_adcAnalytics)->performTelemerty();
        usleep(5000); 
    }   
}

void ADCAnalytics::performTelemerty()
{   
    // number of active downloads
    int counter = 0;

    // preform downloading
    curl_multi_perform(m_telemetryCurlm, &counter);     

    // handle CURL actions (connection errors, download finish, etc.)
    checkCURLMessages();    
} 

但是当我检查卷曲消息时,我得到了:

12-10 13:23:00.845:I / ADC(17248):buffer = HTTP / 1.1 400 Bad Request

12-10 13:23:00.845:I / ADC(17248):X-TraceUrl:/ appstats / details?time = 1355145806563&amp; type = json

12-10 13:23:00.845:I / ADC(17248):Content-Type:text / plain

12-10 13:23:00.845:I / ADC(17248):变化:接受编码

12-10 13:23:00.845:I / ADC(17248):日期:星期一,2012年12月10日13:23:26 GMT

12-10 13:23:00.845:I / ADC(17248):服务器:Google前端

12-10 13:23:00.845:I / ADC(17248):缓存控制:私有

12-10 13:23:00.845:I / ADC(17248):转移编码:分块

似乎在curl_multi_add_handle和curl_multi_perform之间更改了内容类型。有人知道这里有什么问题吗?我该怎么做才能避免更改内容类型?

添加以下代码时

         do {
        while(curl_multi_perform(m_telemetryCurlm, &still_running) ==CURLM_CALL_MULTI_PERFORM);                                 
    } while (still_running);                                                             
设置cURL对象后立即

。请求被发送到服务器,我得到了

12-10 13:11:48.105:I / ADC(16845):buffer = HTTP / 1.1 200 OK

12-10 13:11:48.105:I / ADC(16845):X-TraceUrl:/ appstats / details?time = 1355145133776&amp; type = json

12-10 13:11:48.105:I / ADC(16845):Content-Type:application / json

12-10 13:11:48.105:I / ADC(16845):变化:接受编码

12-10 13:11:48.105:I / ADC(16845):日期:星期一,2012年12月10日13:12:13 GMT

12-10 13:11:48.105:I / ADC(16845):服务器:Google前端

12-10 13:11:48.105:I / ADC(16845):缓存控制:私有

12-10 13:11:48.105:I / ADC(16845):转移编码:分块
所以,我不相信服务器端有问题。

由于

1 个答案:

答案 0 :(得分:0)

您不是要将发送的内容类型与收到的内容类型进行比较吗?