This is a quick example of a simple HTTP client program using the network-socket API that is provided as a part of mbed-os. The program brings up an underlying network interface, and uses it to perform an HTTP transaction over a TCPSocket.

Thu Sep 12 16:00:11 2019 +0100
73:03f443752d8a remove the External address line form sample output

Commit copied from

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 49:1923a727df5b 1 ## Getting started with the network-socket API
mbed_official 0:17bd84fc5087 2
mbed_official 70:8a522080e86d 3 (Note: To see this example in a rendered form you can import into the Arm Mbed Online Compiler, please see [the documentation](
mbed_official 70:8a522080e86d 4
mbed_official 0:17bd84fc5087 5 This is a quick example of a simple HTTP client program using the
mbed_official 33:d470701728e6 6 [network-socket API]( that [Mbed OS]( provides.
mbed_official 0:17bd84fc5087 7
mbed_official 0:17bd84fc5087 8 The program brings up an underlying network interface, and uses it to perform an HTTP
mbed_official 0:17bd84fc5087 9 transaction over a TCPSocket.
mbed_official 0:17bd84fc5087 10
mbed_official 49:1923a727df5b 11 ### Selecting the network interface
mbed_official 49:1923a727df5b 12
mbed_official 61:e61d4d810148 13 This application is able to use any network inteface it finds. Please see the Mbed OS documentationg for [selecting the default network interface](
mbed_official 49:1923a727df5b 14
mbed_official 49:1923a727df5b 15 For example, building on Ethernet enabled boards, you do not do any configuration.
mbed_official 49:1923a727df5b 16
mbed_official 53:0d44278430d3 17 Building for WiFi boards, you need to provide SSID, password and security settings in `mbed_app.json` as instructed in the documentation. For example, like this:
mbed_official 53:0d44278430d3 18
mbed_official 53:0d44278430d3 19 ```
mbed_official 53:0d44278430d3 20 {
mbed_official 53:0d44278430d3 21 "target_overrides": {
mbed_official 53:0d44278430d3 22 "*": {
mbed_official 53:0d44278430d3 23 "platform.stdio-convert-newlines": true,
mbed_official 53:0d44278430d3 24 "": "WIFI",
mbed_official 53:0d44278430d3 25 "nsapi.default-wifi-security": "WPA_WPA2",
mbed_official 53:0d44278430d3 26 "nsapi.default-wifi-ssid": "\"ssid\"",
mbed_official 53:0d44278430d3 27 "nsapi.default-wifi-password": "\"password\""
mbed_official 53:0d44278430d3 28 }
mbed_official 53:0d44278430d3 29 }
mbed_official 53:0d44278430d3 30 }
mbed_official 53:0d44278430d3 31 ```
mbed_official 49:1923a727df5b 32
mbed_official 49:1923a727df5b 33 Building for boards that have more that one network interface, you might need to override `` variable.
mbed_official 0:17bd84fc5087 34
mbed_official 40:afef93b6d854 35 ### Building
mbed_official 40:afef93b6d854 36
mbed_official 40:afef93b6d854 37 ```
mbed_official 40:afef93b6d854 38 mbed compile -t <toolchain> -m <target>
mbed_official 40:afef93b6d854 39 ```
mbed_official 40:afef93b6d854 40
mbed_official 40:afef93b6d854 41 For example, building for K64F using GCC: `mbed compile -t GCC_ARM -m K64F`
mbed_official 24:0449435e2ef2 42
mbed_official 13:ed9e4aa00044 43 ### Expected output ###
mbed_official 13:ed9e4aa00044 44
mbed_official 40:afef93b6d854 45 **Note:** The default serial port baud rate is 9600 bit/s.
mbed_official 40:afef93b6d854 46
mbed_official 13:ed9e4aa00044 47 ```
mbed_official 13:ed9e4aa00044 48 IP address:
mbed_official 13:ed9e4aa00044 49 Netmask:
mbed_official 13:ed9e4aa00044 50 Gateway:
mbed_official 13:ed9e4aa00044 51 sent 39 [GET / HTTP/1.1]
mbed_official 13:ed9e4aa00044 52 recv 173 [HTTP/1.1 200 OK]
mbed_official 13:ed9e4aa00044 53 Done
mbed_official 13:ed9e4aa00044 54 ```
mbed_official 13:ed9e4aa00044 55
mbed_official 0:17bd84fc5087 56 ### Documentation ###
mbed_official 0:17bd84fc5087 57
mbed_official 12:2e7466eba9a3 58 More information on the network-socket API can be found in the [mbed handbook](
mbed_official 33:d470701728e6 59
mbed_official 33:d470701728e6 60 ## Troubleshooting
mbed_official 33:d470701728e6 61
mbed_official 33:d470701728e6 62 If you have problems, you can review the [documentation]( for suggestions on what could be wrong and how to fix it.
mbed_official 73:03f443752d8a 63
mbed_official 73:03f443752d8a 64 ## License and contributions
mbed_official 73:03f443752d8a 65
mbed_official 73:03f443752d8a 66 The software is provided under Apache-2.0 license. Contributions to this project are accepted under the same license. Please see []( for more info.
mbed_official 73:03f443752d8a 67
mbed_official 73:03f443752d8a 68 This project contains code from other projects. The original license text is included in those source files. They must comply with our license guide.
mbed_official 73:03f443752d8a 69