Sending a request to https server.

filipESP
Posts: 74
Joined: Tue Nov 06, 2018 12:42 pm

Sending a request to https server.

Postby filipESP » Tue Nov 06, 2018 2:11 pm

I an trying to download the content of a webpage and I get the response with 307 status code with "a href="/..." message.
The response I got looks like this: HTTP/1.0 307 Temporary Redirect Content-Length: 123 Content-Type: text/html; charset=utf-8 Date: Tue, 06 Nov 2018 09:44:40 GMT Location: "<a href="/oauth/authorize?state=L2FwaS9wcm...=">Temporary Redirect</a>"

I use esp_http_client example and https() function.
The function: esp_http_client_fetch_headers(client) returns -1, and when I comment
this line: if (total_read_len < content_length && content_length <= MAX_HTTP_RECV_BUFFER) {
and in call this function: esp_http_client_read(client, buffer, content_length) I put e.g 512 instead "content_length" I get response with 307 status code.

Code: Select all

static void https()
{
    esp_http_client_config_t config = {

    	.url = "any URL",	
		.host = " any host ",
		.port = 443,
	    .username = "username",           /*!< Using for Http authentication */
	    .password = "password",           /*!< Using for Http authentication */
    };
    esp_http_client_handle_t client = esp_http_client_init(&config);
    esp_err_t err = esp_http_client_perform(client);

    if (err == ESP_OK) {
        ESP_LOGI(TAG, "HTTPS Status = %d, content_length = %d",
                esp_http_client_get_status_code(client),
                esp_http_client_get_content_length(client));
    } else {
        ESP_LOGE(TAG, "Error perform http request %s", esp_err_to_name(err));
    }
    char *buffer = malloc(MAX_HTTP_RECV_BUFFER + 1);
    int content_length =  esp_http_client_fetch_headers(client);
    ESP_LOGW( "TEST content_length", "%d", content_length);
    int total_read_len = 0, read_len;
    if (total_read_len < content_length && content_length <= MAX_HTTP_RECV_BUFFER) {
        read_len = esp_http_client_read(client, buffer, content_length);
        if (read_len <= 0) {
            ESP_LOGE("HTTPS", "Error read data");
    	}

        ESP_LOGW( "HTTPS response: ", "%s", buffer);
    }
    esp_http_client_cleanup(client);
}

filipESP
Posts: 74
Joined: Tue Nov 06, 2018 12:42 pm

Re: Sending a request to https server.

Postby filipESP » Thu Nov 08, 2018 2:36 pm

What is the way to set http path when the data is chunked?

chegewara
Posts: 2378
Joined: Wed Jun 14, 2017 9:00 pm

Re: Sending a request to https server.

Postby chegewara » Fri Nov 09, 2018 9:32 am

https://httpstatuses.com/307
The server SHOULD generate a Location header field in the response containing a URI reference for the different URI. The user agent MAY use the Location field value for automatic redirection. The server's response payload usually contains a short hypertext note with a hyperlink to the different URI(s).
Probably this value which is default 512 is too small in your case MAX_HTTP_RECV_BUFFER. It happened to me and i couldnt parse response from server.

Who is online

Users browsing this forum: BivvyCoder and 88 guests