Socket HTTP Client
Overview
This sample application implements an HTTP(S) client that will do an HTTP or HTTPS request and wait for the response from the HTTP server.
The source code for this sample application can be found at: samples/net/sockets/http_client.
Requirements
Building and Running
You can use this application on a supported board, including running it inside QEMU as described in Networking with QEMU.
Build the http-client sample application like this:
west build -b <board to use> samples/net/sockets/http_client -- -DCONF_FILE=<config file to use>
Enabling TLS support
Enable TLS support in the sample by building the project with the
overlay-tls.conf
overlay file enabled using these commands:
west build -b qemu_x86 samples/net/sockets/http_client -- -DCONF_FILE="prj.conf overlay-tls.conf"
An alternative way is to specify -DOVERLAY_CONFIG=overlay-tls.conf
when
running west build
or cmake
.
The certificate and private key used by the sample can be found in the sample’s
samples/net/sockets/http_client/src/ directory.
The default certificates used by Socket HTTP Client and
https-server.py
program found in the
net-tools project, enable
establishing a secure connection between the samples.
Running http-server in Linux Host
You can run this http-client
sample application in QEMU
and run the http-server.py
(from net-tools) on a Linux host.
To use QEMU for testing, follow the Networking with QEMU guide.
In a terminal window:
$ ./http-server.py
Run http-client
application in QEMU:
west build -b qemu_x86 samples/net/sockets/http_client -- -DCONF_FILE=prj.conf
west build -t run
Note that http-server.py
must be running in the Linux host terminal window
before you start the http-client application in QEMU.
Exit QEMU by pressing CTRL+A x.
You can verify TLS communication with a Linux host as well. Just use the
https-server.py
program in net-tools project.