HTTP Methods Example
Demonstrates using HTTP Client APIs to issue an HTTP request with a custom header and handle the response. It also demonstrates reading a line from the ZentriOS terminal UART.
- SDK directory:
- Zentri App Store:
API Features Demonstrated
- Protocols/HTTP Client
- Custom Commands
This app works on:
- AMW004 - Zentri Mackerel evaluation board
- AMW106 - Zentri Moray evaluation board
- NXP-SCCK - NXP Secure Cloud Connectivity Kit
Requirements and Prerequisites
Requires a ZentriOS evaluation board.
This app uses the RequestBin site to inspect the HTTP request sent by the app.
Open a ZentriOS serial terminal to the device. See Getting Started, Opening a ZentriOS Terminal.
This app assumes your ZentriOS device is set up with the credentials to join your local network. If you have not already set up network credentials, on the ZentriOS terminal, run the commands:
network_up -s save
See the Wi-Fi Command API documentation for network_up and save.
On compiling and running the app, it requests a Bin URL from RequestBin.
Start HTTP Methods Example app With your computer's webbrowser, goto: http://requestb.in/ On the RequestBin webpage, click the button: 'Create a RequestBin' A 'Bin URL' is displayed at the top of the page Enter the Bin URL here:
Open the RequestBin site in a web browser and click the
Create a RequestBin button.
Type in the supplied Bin URL at the ZentriOS terminal.
Refresh the RequestBin page to see inspect the results of the request.
Displays the opening message and prompts for the RequestBin URL using a call to
This calls zn_cmd_set_console_enabled to disable the console, then calls zn_uart_receive_bytes.
The function handles the requirement for
CR-LF by calling zn_uart_transmit_bytes to ensure that a line feed is sent after a carriage return.
It then enables the console again with another call to zn_cmd_set_console_enabled.
See http_get.c for the details of assembling the HTTP request and reading the response, with calls to the HTTP Client API: zn_http_open_request, zn_http_add_header, zn_http_receive_response, zn_http_read and zn_http_close.