Submit CSR to server
This commit is contained in:
@ -128,6 +128,7 @@ char *http_client_exec(const http_request_opts *opts)
|
||||
.url = opts->url,
|
||||
.disable_auto_redirect = true,
|
||||
.cert_pem = opts->root_ca,
|
||||
.method = opts->method == MethodPOST ? HTTP_METHOD_POST : HTTP_METHOD_GET,
|
||||
};
|
||||
esp_http_client_handle_t client = esp_http_client_init(&config);
|
||||
|
||||
@ -138,6 +139,16 @@ char *http_client_exec(const http_request_opts *opts)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (opts->content_type)
|
||||
{
|
||||
esp_http_client_set_header(client, "Content-Type", opts->content_type);
|
||||
}
|
||||
|
||||
if (opts->body)
|
||||
{
|
||||
esp_http_client_set_post_field(client, opts->body, strlen(opts->body));
|
||||
}
|
||||
|
||||
ESP_LOGD(TAG, "esp_http_client_perform start");
|
||||
esp_err_t err = esp_http_client_perform(client);
|
||||
ESP_LOGD(TAG, "esp_http_client_perform end");
|
||||
@ -158,6 +169,12 @@ char *http_client_exec(const http_request_opts *opts)
|
||||
if (status < 200 || status > 299)
|
||||
{
|
||||
ESP_LOGE(TAG, "HTTP request failed with status %d!", status);
|
||||
|
||||
if (status > 299)
|
||||
{
|
||||
ESP_LOGI(TAG, "HTTP Response Body = %s", local_response_buffer);
|
||||
}
|
||||
|
||||
free(local_response_buffer);
|
||||
return NULL;
|
||||
}
|
||||
@ -165,4 +182,69 @@ char *http_client_exec(const http_request_opts *opts)
|
||||
local_response_buffer[resp_len] = 0;
|
||||
|
||||
return local_response_buffer;
|
||||
}
|
||||
|
||||
static uint32_t uri[] = {
|
||||
0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */
|
||||
|
||||
/* ?>=< ;:98 7654 3210 /.-, +*)( '&%$ #"! */
|
||||
0xd000002d, /* 1101 0000 0000 0000 0000 0000 0010 1101 */
|
||||
|
||||
/* _^]\ [ZYX WVUT SRQP ONML KJIH GFED CBA@ */
|
||||
0x50000000, /* 0101 0000 0000 0000 0000 0000 0000 0000 */
|
||||
|
||||
/* ~}| {zyx wvut srqp onml kjih gfed cba` */
|
||||
0xb8000001, /* 1011 1000 0000 0000 0000 0000 0000 0001 */
|
||||
|
||||
0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */
|
||||
0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */
|
||||
0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */
|
||||
0xffffffff /* 1111 1111 1111 1111 1111 1111 1111 1111 */
|
||||
};
|
||||
|
||||
static u_char hex[] = "0123456789ABCDEF";
|
||||
|
||||
size_t http_client_escape_uri(unsigned char *dst, const u_char *src, size_t size)
|
||||
{
|
||||
size_t n;
|
||||
|
||||
if (dst == NULL)
|
||||
{
|
||||
/* find the number of the characters to be escaped */
|
||||
n = 0;
|
||||
|
||||
while (size)
|
||||
{
|
||||
if (uri[*src >> 5] & (1U << (*src & 0x1f)))
|
||||
{
|
||||
n++;
|
||||
n++;
|
||||
}
|
||||
src++;
|
||||
size--;
|
||||
n++;
|
||||
}
|
||||
|
||||
return n + 1;
|
||||
}
|
||||
|
||||
while (size)
|
||||
{
|
||||
if (uri[*src >> 5] & (1U << (*src & 0x1f)))
|
||||
{
|
||||
*dst++ = '%';
|
||||
*dst++ = hex[*src >> 4];
|
||||
*dst++ = hex[*src & 0xf];
|
||||
src++;
|
||||
}
|
||||
else
|
||||
{
|
||||
*dst++ = *src++;
|
||||
}
|
||||
size--;
|
||||
}
|
||||
|
||||
*dst++ = '\0';
|
||||
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user