[英]header content-type changes between curl_multi_add_handle and curl_multi_perform
I have created a cURL post with headers in a c++ application: 我在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);
I have created a thread to call 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();
}
but when I check the curl messages I get: 但是当我查看curl消息时,我得到:
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):缓冲区= HTTP / 1.1 400错误请求
12-10 13:23:00.845: I/ADC(17248): X-TraceUrl: /appstats/details?time=1355145806563&type=json 12-10 13:23:00.845:I / ADC(17248):X-TraceUrl:/ appstats / details?time = 1355145806563&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): Vary: Accept-Encoding 12-10 13:23:00.845:I / ADC(17248):不同:接受编码
12-10 13:23:00.845: I/ADC(17248): Date: Mon, 10 Dec 2012 13:23:26 GMT 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): Server: Google Frontend 12-10 13:23:00.845:I / ADC(17248):服务器:Google Frontend
12-10 13:23:00.845: I/ADC(17248): Cache-Control: private 12-10 13:23:00.845:I / ADC(17248):缓存控制:私有
12-10 13:23:00.845: I/ADC(17248): Transfer-Encoding: chunked 12-10 13:23:00.845:I / ADC(17248):传输编码:分块
It seems that the content-type is changed between curl_multi_add_handle and curl_multi_perform. 似乎内容类型在curl_multi_add_handle和curl_multi_perform之间更改。 Does anybody has any idea what is wrong here?
有人知道这里有什么问题吗? What can I do to avoid content-type to change?
如何避免内容类型更改?
When adding the following code 添加以下代码时
do {
while(curl_multi_perform(m_telemetryCurlm, &still_running) ==CURLM_CALL_MULTI_PERFORM);
} while (still_running);
immediately after setting the cURL object. 设置cURL对象后立即进行。 The request is sent to the server and I get
该请求被发送到服务器,我得到
12-10 13:11:48.105: I/ADC(16845): buffer = HTTP/1.1 200 OK 12-10 13:11:48.105:I / ADC(16845):缓冲区= HTTP / 1.1 200 OK
12-10 13:11:48.105: I/ADC(16845): X-TraceUrl: /appstats/details?time=1355145133776&type=json 12-10 13:11:48.105:I / ADC(16845):X-TraceUrl:/ appstats / details?time = 1355145133776&type = json
12-10 13:11:48.105: I/ADC(16845): Content-Type: application/json 12-10 13:11:48.105:I / ADC(16845):内容类型:application / json
12-10 13:11:48.105: I/ADC(16845): Vary: Accept-Encoding 12-10 13:11:48.105:I / ADC(16845):不同:接受编码
12-10 13:11:48.105: I/ADC(16845): Date: Mon, 10 Dec 2012 13:12:13 GMT 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): Server: Google Frontend 12-10 13:11:48.105:I / ADC(16845):服务器:Google Frontend
12-10 13:11:48.105: I/ADC(16845): Cache-Control: private 12-10 13:11:48.105:I / ADC(16845):缓存控制:专用
12-10 13:11:48.105: I/ADC(16845): Transfer-Encoding: chunked 12-10 13:11:48.105:I / ADC(16845):传输编码:分块
So, I don't believe is something wrong on the server side. 因此,我不认为服务器端有问题。
Thanks 谢谢
您不是将发送的内容类型与接收的内容类型进行比较吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.