Multiprotocol HTTP Client

Browse source code on GitHub

Overview

This sample uses the multiprotocol HTTP client over HTTP/2, in two parts:

  • A synchronous session, with a GET request and a PUT request whose body is streamed through the payload callback.

  • An asynchronous session, with three GET requests sent back to back and their responses delivered through the callback, interleaved on one connection.

Built with the TLS overlay, it does the same over HTTPS. The server has to accept PUT requests for the upload to be answered with success.

The source code for this sample application can be found at: samples/net/sockets/http_client_multiprotocol.

Requirements

  • Networking with the host system

  • An HTTP/2 server. In the clear, the server has to accept HTTP/2 with prior knowledge on port 8080; over TLS, it has to offer h2 through ALPN on port 4443 with the https-server.pem certificate from the net-tools project, which the sample trusts for the host name localhost.

Building and Running

Build and run the sample on a supported board, or on native_sim as described in Networking with native_sim board:

west build -b native_sim samples/net/sockets/http_client_multiprotocol
west build -t run

Add the tls.conf Kconfig fragment for HTTPS:

west build -b native_sim samples/net/sockets/http_client_multiprotocol -- -DCONF_FILE="prj.conf tls.conf"
west build -t run

The server address is taken from the CONFIG_NET_CONFIG_PEER_IPV4_ADDR option in prj.conf.

See also

Multiprotocol HTTP client API
TLS credentials management