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 Gecko OS terminal UART.
- SDK directory:
API Features Demonstrated
This app works on:
Requirements and Prerequisites
Requires a Gecko OS evaluation board, such as a WGM160P_eval.
This app uses the RequestBin site to inspect the HTTP request sent by the app.
Open a Gecko OS serial terminal to the device. See Getting Started, Opening a Gecko OS Terminal.
This app assumes your Gecko OS device is set up with the credentials to join your local network. If you have not already set up network credentials, on the Gecko OS 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 Gecko OS terminal.
Refresh the RequestBin page to inspect the results of the request.
Displays the opening message and prompts for the RequestBin URL using a call to
This calls gos_cmd_set_console_enabled to disable the console, then calls gos_uart_receive_bytes.
The function handles the requirement for
CR-LF by calling gos_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 gos_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: gos_http_open_request, gos_http_add_header, gos_http_receive_response, gos_http_read and gos_http_close.