esp8266在HTTP——ota的时候,想要打印接收头,但是http_parser_execute()这个函数处理完了,不知道如何打印出响应头
用代码块功能插入代码,请勿粘贴截图
bool bParsed = false;
int parsed=0;
http_parser httpParser;
http_parser_settings httpSettings;
// 初使化解析器及回调函数
http_parser_init(&httpParser, HTTP_REQUEST);
http_parser_settings_init(&httpSettings);
if (client->state < HTTP_STATE_REQ_COMPLETE_HEADER) {
return ESP_FAIL;
}
client->state = HTTP_STATE_REQ_COMPLETE_DATA;
esp_http_buffer_t *buffer = client->response->buffer;
client->response->status_code = -1;
//char *p;
//p=(char *)(&(client->response->headers));
//ESP_LOGI(TAG, "client_response_headers_sizeof = %d",sizeof(client->response->headers));
//for(int i=0;i<400;i++)
//{
// ESP_LOGI("", "%02x",*p++);
//putchar(*p++);
//}
while (client->state < HTTP_STATE_RES_COMPLETE_HEADER) {
buffer->len = esp_transport_read(client->transport, buffer->data, client->buffer_size, client->timeout_ms);
if (buffer->len < 0) {
return ESP_FAIL;
}
parsed= http_parser_execute(client->parser, client->parser_settings, buffer->data, buffer->len);
}
printf("http_parser_execute => parsebytes:[%d] parseok:[%d] \n", parsed, bParsed);
// if(bParsed)
// {
// printf("url: [%s] \n", client.connection_info.url);
//printf("status: [%s] \n", client->);
// printf("heads: \n");
/* for (std::map<std::string, std::string>::iterator iter = mapHeadField.begin(); iter != mapHeadField.end(); ++iter)
{
printf("\t %s : %s \n", iter->first.c_str(), iter->second.c_str());
}
printf("body: [%s] \n", strBody.c_str());*/
// }
ESP_LOGD(TAG, "content_length = %d", client->response->content_length);
ESP_LOGI(TAG, "content_length = %d", client->response->content_length);
if (client->response->content_length <= 0) {
client->response->is_chunked = true;
return 0;
}
return client->response->content_length;