issue in using esp_http_client

vivek.vaghela
Posts: 10
Joined: Fri Oct 05, 2018 10:31 am

issue in using esp_http_client

Postby vivek.vaghela » Mon Nov 26, 2018 5:49 am

I have one http client application which communicates to the Cloud. I use http client API's as follows:
1> esp_http_client_init.
2> esp_http_client_set_header to set the headers.
3> then 'esp_http_client_open' to open the connection.
4> esp_http_client_get_content_length
5> esp_http_client_write
6> esp_http_client_fetch_headers
7> esp_http_client_get_status_code
8> esp_http_client_is_chunked_response
9> esp_http_client_get_content_length
10> esp_http_client_get_status_code
11> esp_http_client_read
12> esp_http_client_cleanup
Currently I am opening a connection and closing it for every request.
But while trying to open the connection only at one time for few requests, I faced One issue that I am not able to add header using 'esp_http_client_set_header' after 'esp_http_client_open'.
using 'esp_http_client_set_header' after 'esp_http_client_open' doesn't writes header to the socket means it don't send those headers which are set after the 'esp_http_client_open' and my request goes without those headers and I receive negative response from cloud.
The esp_http_client writes only those headers to socket which are set before esp_http_client_open.
So Is there a way to set headers after opening the connection(esp_http_client_open) as I don't wan't to close my socket on each request?

vivek.vaghela
Posts: 10
Joined: Fri Oct 05, 2018 10:31 am

Re: issue in using esp_http_client

Postby vivek.vaghela » Tue Nov 27, 2018 7:05 pm

Hi there,
Please Guide Me. Thanks In advance.

vivek.vaghela
Posts: 10
Joined: Fri Oct 05, 2018 10:31 am

Re: issue in using esp_http_client

Postby vivek.vaghela » Wed Nov 28, 2018 4:46 am

Currently I am using esp-idf-v3.1-beta1.

vivek.vaghela
Posts: 10
Joined: Fri Oct 05, 2018 10:31 am

Re: issue in using esp_http_client

Postby vivek.vaghela » Wed Nov 28, 2018 5:55 am

I think the fix for this issue is in branch release/v3.2(https://github.com/espressif/esp-idf/bl ... p_client.c) esp_http_client module but not yet released, am I wright?
Should I use this branch to resolve my issue?

ESP_Alvin
Posts: 211
Joined: Thu May 17, 2018 2:26 am

Re: issue in using esp_http_client

Postby ESP_Alvin » Wed Nov 28, 2018 5:56 am

Hi, vivek.vaghela

Sorry for the reply, our engineer has been looking into this and will reply soon.

Thanks.

Alvin
Best Regards

ESP_tuanpm
Posts: 14
Joined: Sat Dec 05, 2015 7:59 am

Re: issue in using esp_http_client

Postby ESP_tuanpm » Thu Nov 29, 2018 3:16 am

vivek.vaghela wrote:
Mon Nov 26, 2018 5:49 am
I have one http client application which communicates to the Cloud. I use http client API's as follows:
1> esp_http_client_init.
2> esp_http_client_set_header to set the headers.
3> then 'esp_http_client_open' to open the connection.
4> esp_http_client_get_content_length
5> esp_http_client_write
6> esp_http_client_fetch_headers
7> esp_http_client_get_status_code
8> esp_http_client_is_chunked_response
9> esp_http_client_get_content_length
10> esp_http_client_get_status_code
11> esp_http_client_read
12> esp_http_client_cleanup
Currently I am opening a connection and closing it for every request.
But while trying to open the connection only at one time for few requests, I faced One issue that I am not able to add header using 'esp_http_client_set_header' after 'esp_http_client_open'.
using 'esp_http_client_set_header' after 'esp_http_client_open' doesn't writes header to the socket means it don't send those headers which are set after the 'esp_http_client_open' and my request goes without those headers and I receive negative response from cloud.
The esp_http_client writes only those headers to socket which are set before esp_http_client_open.
So Is there a way to set headers after opening the connection(esp_http_client_open) as I don't wan't to close my socket on each request?
Hi @vivek.vaghela The esp_http_client_open will open the connection and write all http datas (include http header). If you want to set the HTTP header, you need to use esp_http_client_set_header before calling the esp_http_client_open

There is a way to write the HTTP header after esp_http_client_open by using esp_http_client_set_header in HTTP_EVENT_ON_CONNECTED event

vivek.vaghela
Posts: 10
Joined: Fri Oct 05, 2018 10:31 am

Re: issue in using esp_http_client

Postby vivek.vaghela » Thu Nov 29, 2018 7:23 am

Hi ESP_tuanpm ,
Thanks for the answer, But in my case:
I don't want to close the connection every time, after opening the connection first time for the first request I can call the esp_http_client_set_header api in the 'HTTP_EVENT_ON_CONNECTED', but what to do for the next requests without closing the connection, as the HTTP_EVENT_ON_CONNECTED will occur for the first time only.

vivek.vaghela
Posts: 10
Joined: Fri Oct 05, 2018 10:31 am

Re: issue in using esp_http_client

Postby vivek.vaghela » Thu Nov 29, 2018 7:30 am

vivek.vaghela wrote:
Wed Nov 28, 2018 5:55 am
I think the fix for this issue is in branch release/v3.2(https://github.com/espressif/esp-idf/bl ... p_client.c) esp_http_client module but not yet released, am I wright?
Should I use this branch to resolve my issue?
As there are new APIs esp_http_client_connect and esp_http_client_request_send in branch release/v3.2 which are separating the esp_http_client_open's process.
Is this wright, can the above mention branch will solve my problem?

Who is online

Users browsing this forum: No registered users and 78 guests