cancel
Showing results for 
Search instead for 
Did you mean: 

WICED Studio Wi-Fi Combo

Anonymous
Not applicable

HI , I am a starter with http2. Now I want to make a http2 get request with MFI SDK4.0.1 .The request is like this:

:method = GET

:scheme = https

:path = /{{API version}}/directives

authorization = Bearer {{YOUR_ACCESS_TOKEN}}

the wirte header and write request is right ,but the http client will disconnect immediately after http request flush.It is normal?

Below is how I creat a get request:

static const char* request_uris[] =

{

  [0] = "/get"

};

    WPRINT_APP_INFO( ( "Resolving IP address of HTTPS server\n" ) );
    wiced_hostname_lookup(CONNECTION_SERVER_HOST, &ip_address, DNS_TIMEOUT_MS);
    WPRINT_APP_INFO( ( "%s is at %u.%u.%u.%u\n", CONNECTION_SERVER_HOST,
                                                 (uint8_t)(GET_IPV4_ADDRESS(ip_address) >> 24),
                                                 (uint8_t)(GET_IPV4_ADDRESS(ip_address) >> 16),
                                                 (uint8_t)(GET_IPV4_ADDRESS(ip_address) >> 8),
                                                 (uint8_t)(GET_IPV4_ADDRESS(ip_address) >> 0) ) );

    /* Initialize the root CA certificate */
    result = wiced_tls_init_root_ca_certificates( amazon_root_ca_certificate, strlen( amazon_root_ca_certificate ) );
    if ( result != WICED_SUCCESS )
    {
        WPRINT_APP_INFO( ( "Error: Root CA certificate failed to initialize: %u\n", result) );
    }
    WPRINT_APP_INFO(("Root CA certificate successed to initialize!\n"));

    sprintf(https_header,":method = GET\r\n:scheme = https\r\n:path = /v20160207/directives\r\nauthorization = Bearer %s\r\n",access_token);
    WPRINT_APP_INFO(("\n%s\n\n", https_header));

    result = http_client_init( &client, WICED_STA_INTERFACE, event_handler, NULL );

    if (result == WICED_SUCCESS)
{
    WPRINT_APP_INFO( ( "http inited success  %d\n", result ) );
}
else WPRINT_APP_INFO( ( "http failed to init %d\n", result ) );
    /* configure HTTP client parameters */
    client_configuration.flag = HTTP_CLIENT_CONFIG_FLAG_SERVER_NAME | HTTP_CLIENT_CONFIG_FLAG_MAX_FRAGMENT_LEN;
    client_configuration.server_name = (uint8_t*)CONNECTION_SERVER_HOST;
    client_configuration.max_fragment_length = TLS_FRAGMENT_LENGTH_4096;
    http_client_configure(&client, &client_configuration);

    result = http_client_connect( &client, (const wiced_ip_address_t*)&ip_address, SERVER_PORT, HTTP_USE_TLS, CONNECT_TIMEOUT_MS );
    if (result == WICED_SUCCESS)
    {
    WPRINT_APP_INFO( ( "http connected %d\n", result ) );

        header[0].field        = HTTP_HEADER_HOST;
        header[0].field_length = sizeof( HTTP_HEADER_HOST) - 1;
        header[0].value        = CONNECTION_SERVER_HOST;
        header[0].value_length = sizeof( CONNECTION_SERVER_HOST ) - 1;

char *http_get_length_string = malloc(10);

     itoa(strlen(https_header),http_get_length_string,10);


header[2].field        = HTTP_HEADER_CONTENT_TYPE;
header[2].field_length = sizeof( HTTP_HEADER_CONTENT_TYPE ) - 1;
header[2].value        = "application/x-www-form-urlencoded";
    header[2].value_length = sizeof( "application/x-www-form-urlencoded" ) - 1;
        header[1].field        = HTTP_HEADER_CONTENT_LENGTH;
header[1].field_length = sizeof( HTTP_HEADER_CONTENT_LENGTH ) - 1;
header[1].value        = http_get_length_string;
header[1].value_length = strlen( http_get_length_string );

    header[3].field        = "Connection: ";
    header[3].field_length = sizeof("Connection: ") - 1;
    header[3].value        = "Keep-Alive";
    header[3].value_length = sizeof( "Keep-Alive" ) - 1;
http_request_init( &requests[0], &client, HTTP_GET, request_uris[0], HTTP_2 );
for(uint8_t i=0;i<4;i++)
{
http_request_write_header( &requests[0], &header, 1 );
WPRINT_APP_INFO( ( "http_request_write_header %d result : %d \n" ,i,result) );
}
http_request_write_end_header( &requests[0] );
http_request_write(&requests[0],(uint8_t *)https_header,sizeof(https_header)-1);//write body
WPRINT_APP_INFO( ( "http_request_write result : %d \n" ,result) );
http_request_write_end_header( &requests[0] );
http_request_flush( &requests[0] );
    }
    else WPRINT_APP_INFO( ( "http failed to connect %d\n", result ) );
0 Likes
Reply
1 Solution
Moderator
Moderator

You can refer to test.http2 example in WICED SDK 6.1 for the same.

View solution in original post

0 Likes
Reply
10 Replies
Anonymous
Not applicable

anyu

0 Likes
Reply
Contributor II

check your CONTENT_LENGTH value , which should not be the https_header size !

0 Likes
Reply
Anonymous
Not applicable

Yes,I found this problem and modify it.But it still not work.

0 Likes
Reply
Anonymous
Not applicable

I gave up the normal way to send request and try just use "wiced_tcp_stream_write" function to send the whole string as

":method = GET

:scheme = https

:path = /v20160207/directives

authorization = Bearer Atza|IwEBII8TeS8VNozTAhMww_krgKh8ZTMml0veve6BKjRynqUVAxs0YqiKOTyvr2TtMN8o0u5bP24RH5gy24iQuY6lU56kBXyfVWX4eeNztkqaxmhlkyA5rQozxIsOI6EpF7Tb_PIejNt2z-6ynztTP1GQwrmuG0-KrbpY7U3luc-DhZrS8DPCWwuRYIRuQ9TLS0AnZLElQdj-lIlxRiERxaObmM7D0HfvMO8L4vW3L2X1XTlBZKKTRGXfwi82IZeCoy6Vo0Tqt-3usc3Tnv_nxtXkBA9kGxXhLa8eXdpAoxi6X1pbf51No2FUceNmpC48tUxrHt7QJZdRAK7BCZK8RFgQINOkgspksNDdl4fAUEQYk4MXBxPaK78BE5zvn9Rb23Q2C4eidsW5_BcBvag7ZJwdy3sTjumZqSxie_n_taJlXYX9k9fM1LnL_KVclL5_mTFiPrjQXBXDwaeDsRlQAI8tsY6GWIrKbScJbw60E0NYdmMr-Xsg8com9q-7Udgg0chOOtyc8n6LW7jR5SDwEe-wM4J1SEHYlGyZFb5Vn3r0odrYHSBrkv57Nm7MABHfmW9xxxx"

.What I found is the  "tcp_stream->socket->tls_context->context.ext_max_fragment_length " in the "wiced_tcpip_common.c" file "wiced_tcp_stream_write" function is alway 176 no matter how I set the client_configuration.max_fragment_length.

Maybe that is the reason cause the error?

0 Likes
Reply
Honored Contributor

I test on sdk-3.7.0-7, using snip.httpbin_org:

httpbin_org has below setting:

client_configuration.max_fragment_length = TLS_FRAGMENT_LENGTH_1024;

However, in wiced_tcp_stream_write() I add below print:

    if (tcp_stream->socket->tls_context != NULL )

    {

printf("ext_max_fragment_length=%u\n", (unsigned) tcp_stream->socket->tls_context->context.ext_max_fragment_length);

        max_fragment_length = tcp_stream->socket->tls_context->context.ext_max_fragment_length;

    }

Then I got:

ext_max_fragment_length=16384

Maybe something wrong for applying max_fragment_length setting?

vsharash

Anonymous
Not applicable

Default maximum fragment size is 16384.

If the client sends maximum fragment length, server will respond to same maximum fragment length value if it support that length.

In this case we suspect the server doesn't support 1024 where the client is continuing its communication using default length. Please check if server has support of maximum fragment length extension.

Honored Contributor

rash wrote:

Default maximum fragment size is 16384.

If the client sends maximum fragment length, server will respond to same maximum fragment length value if it support that length.

In this case we suspect the server doesn't support 1024 where the client is continuing its communication using default length. Please check if server has support of maximum fragment length extension.

I use snip.httpbin_org to test.

You demonstrate the usage of setting max_fragment_length by snip.httpbin_org, but it does not work.

Then maybe it's cypress team's responsibility to check this.

Anonymous
Not applicable

mifobttajakewtorres

0 Likes
Reply
Honored Contributor

jackson_lv wrote:

HI , I am a starter with http2. Now I want to make a http2 get request with MFI SDK4.0.1 .The request is like this:

Now there is a   HTTP2_client library in wiced-studio-5.0.

Moderator
Moderator

You can refer to test.http2 example in WICED SDK 6.1 for the same.

View solution in original post

0 Likes
Reply