2021-02-04 01:36 AM
Hello everyone,
I'm using the STM32F769I-DISCO evaluation board to perform a SSL connection using the MBEDTLS and LWIP Middlewares.
I have found the example for this evaluation board:
This is very helpful to me and I achieve to perform the following connections:
The server where I trying to POST the JSON is "reqbin.com".
The POST that I'm performing is the following:
"POST /echo/post/json HTTP/1.1\nHost: reqbin.com\nContent-Type: application/json\nContent-Length: 8\n\n{\"Id\":7}"
The functions that I'm using to write and read are the following:
/*
* 6. Write the POST request
*/
mbedtls_printf( " > Write to server:" );
sprintf((char *) buf, POST_REQUEST);
len = strlen((char *) buf);
while((ret = mbedtls_ssl_write(&ssl, buf, len)) <= 0)
{
if( ret != MBEDTLS_ERR_SSL_WANT_READ && ret != MBEDTLS_ERR_SSL_WANT_WRITE )
{
mbedtls_printf( " failed\n ! mbedtls_ssl_write returned %d\n\n", ret );
goto exit;
}
}
len = ret;
mbedtls_printf(" %d bytes written\n\n%s", len, (char *) buf);
/*
* 7. Read the HTTP response
*/
mbedtls_printf(" < Read from server:");
do
{
len = sizeof( buf ) - 1;
memset( buf, 0, sizeof( buf ) );
ret = mbedtls_ssl_read( &ssl, buf, len );
if(ret == MBEDTLS_ERR_SSL_WANT_READ || ret == MBEDTLS_ERR_SSL_WANT_WRITE)
{
continue;
}
if(ret == MBEDTLS_ERR_SSL_PEER_CLOSE_NOTIFY)
{
break;
}
if(ret < 0)
{
mbedtls_printf( "failed\n ! mbedtls_ssl_read returned %d\n\n", ret );
break;
}
if(ret == 0)
{
mbedtls_printf( "\n\nEOF\n\n" );
break;
}
len = ret;
mbedtls_printf( " %d bytes read\n\n%s", len, (char *) buf );
}
while(1);
The response of the server isi always 403 Forbidden, and I don't know where is the error.
I'm not an expert in these topics and some help will be very useful for me. I'm not using any type of certification and I think it's not necessary.
Thank you in advance.