-->
Page 1 of 3

A simple HTTP client to make GET and POST requests

PostPosted: Thu Apr 09, 2015 8:53 am
by Caer
Hello everyone,

Let's say your ESP8266 acquires data from a sensor. You want to periodically send it on a remote webserver for logging, on a shared host for instance.
The easiest solution is to POST data on HTTP (like a form on a web page would).

Here is a simple library that will do the HTTP requests for you:
https://github.com/Caerbannog/esphttpclient


  • Easy to use.
  • Supports multiple requests in parallel.
  • Supports GET and POST requests.
  • Tested with Espressif SDK v1.0.0

Installing
If your project looks like esphttpd from Sprite_tm:
Code: Select allgit clone http://git.spritesserver.nl/esphttpd.git/
cd esphttpd
git submodule add https://github.com/Caerbannog/esphttpclient.git lib/esphttpclient
git submodule update --init

Now append lib/esphttpclient to the following Makefile line and you should be ready:
Code: Select allMODULES = driver user lib/esphttpclient

Example GET
Include httpclient.h from user_main.c then add this line to perform a single request and display your public IP address.
Code: Select allhttp_get("http://wtfismyip.com/text", "", http_callback_example);

The output looks like this. It is a success because the 200 code means OK. You can now write your own function to replace http_callback_example.
Code: Select allhttp_status=200
strlen(full_response)=244
body_size=15
body=208.97.177.124
<EOF>

Example POST
To send sensor data use http_post as follows. If you are not interested in the response you can pass NULL for the callback function.
Code: Select allhttp_post("http://httpbin.org/post", "first_word=hello&second_word=world", "", http_callback_example);


Pull requests are welcome.

Re: A simple HTTP client to make GET and POST requests

PostPosted: Mon Apr 13, 2015 9:59 am
by Sprite_tm
Oooh, that looks fancy. I've written my own variant of this but never made it public standaline. I'll now probably take this and use it. I owe you a beer :)

Re: A simple HTTP client to make GET and POST requests

PostPosted: Wed Jun 10, 2015 3:02 am
by Caer
Just a heads up: two kind souls added support for HTTPS and custom request headers.

https://github.com/Caerbannog/esphttpclient

Re: A simple HTTP client to make GET and POST requests

PostPosted: Mon Jan 16, 2017 12:46 pm
by MickeN89
Having issues with the "user_callback_example" in http_get("http://wtfismyip.com/text","",http_callback user_callback);
getting undefined reference
any Ideas?
have cloned your project and made the changes you name and everything...