esp_http_client get data with some error
Posted: Sun Oct 11, 2020 11:03 am
I can get json data from url http://t.weather.itboy.net/api/weather/city/101030100 currectly , but when i use esp_http_client perform this query, I get HTTP_CLIENT: HTTP GET Status = 200, content_length = -1, and I can't get currect response , I use esp_http_client_read_response method to read the response ,
http://t.weather.itboy.net/api/weather/city/101030100
there is whole code
there is whole output:
I (2278) HTTP_CLIENT: HTTP GET response success:len = 529 data = "10","high":"高温 24℃","low":"低温 14℃","ymd":"2020-10-10","week":"星期六","sunrise":"06:16","sunset":"17:40","aqi":130,"fx":"南风","fl":"2级","type":"霾","notice":"雾霾来袭,戴好口罩再出门"}}}
0
�霾来袭,戴好口罩再出门"},{"date":"25","high":"高温 26℃","low":"低温 16℃","ymd":"2020-10-25","week":"星期日","sunrise":"06:31","sunset":"17:19","aqi":154,"fx":"南风","fl":"4级","type":"霾","notice":"雾霾来袭,戴好口罩再出门"}],"yesterday":{"date":m��?|��?X��?X��?
I (2318) HTTP_CLIENT: HTTP GET Status = 200, content_length = -1
I (2328) HTTP_CLIENT: HTTP_EVENT_DISCONNECTED
I (2328) HTTP_CLIENT: Finish http example
http://t.weather.itboy.net/api/weather/city/101030100
there is whole code
- static void http_rest_with_hostname_path(void)
- {
- esp_http_client_config_t config = {
- .host = "t.weather.itboy.net",
- .path = "/api/weather/city/101030100",
- .transport_type = HTTP_TRANSPORT_OVER_TCP,
- .event_handler = _http_event_handler,
- };
- esp_http_client_handle_t client = esp_http_client_init(&config);
- // GET
- esp_err_t err = esp_http_client_perform(client);
- // add logic code in here
- int read_len = 0;
- char buf[10024] = {0};
- read_len = esp_http_client_read_response(client, buf, 10024);
- ESP_LOGI(TAG, "HTTP GET response success:len = %d data = %100s", strlen(buf), buf);
- if (err == ESP_OK)
- {
- ESP_LOGI(TAG, "HTTP GET Status = %d, content_length = %d",
- esp_http_client_get_status_code(client),
- esp_http_client_get_content_length(client));
- }
- else
- {
- ESP_LOGE(TAG, "HTTP GET request failed: %s", esp_err_to_name(err));
- }
- esp_http_client_cleanup(client);
- }
there is whole output:
I (2278) HTTP_CLIENT: HTTP GET response success:len = 529 data = "10","high":"高温 24℃","low":"低温 14℃","ymd":"2020-10-10","week":"星期六","sunrise":"06:16","sunset":"17:40","aqi":130,"fx":"南风","fl":"2级","type":"霾","notice":"雾霾来袭,戴好口罩再出门"}}}
0
�霾来袭,戴好口罩再出门"},{"date":"25","high":"高温 26℃","low":"低温 16℃","ymd":"2020-10-25","week":"星期日","sunrise":"06:31","sunset":"17:19","aqi":154,"fx":"南风","fl":"4级","type":"霾","notice":"雾霾来袭,戴好口罩再出门"}],"yesterday":{"date":m��?|��?X��?X��?
I (2318) HTTP_CLIENT: HTTP GET Status = 200, content_length = -1
I (2328) HTTP_CLIENT: HTTP_EVENT_DISCONNECTED
I (2328) HTTP_CLIENT: Finish http example