Code Monkey home page Code Monkey logo

esp8266-restclient's People

Contributors

cookys avatar csquared avatar dakaz avatar ianmercer avatar jamesward avatar mikaelgu80 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

esp8266-restclient's Issues

ESP32 - wifi.h

Hi, i use your library successfully with ESP8266 for some months now...
Recently i had to switch to ESP32 due to performance issues on EpaperDisplays, now in general your library is based on esp8266wifi.h however ESP32 requires wifi.h which seems to be the new naming.....at least for ESP32. So I did change the library include in the header file of your code....no errors.....but also no output when i try to make a get on a restful server....which works well on ESP8266.

Any idea what needs to be considered on top in order to make it work with "wifi.h"?

Highly appreciate your thoughts and check. Regards Norbert

ssl: connect by IP (one domain) verify by Host header (another domain)

How about this case:

server nginx config

server {
    server_name api.dev;
}

https://github.com/bscheshirwork/docker-yii2-app-advanced-rbac/blob/d7303e2d0c951cc44516c55950ddc6dc2f9f4d41/nginx-conf/nginx.conf#L108

server certificate CN = api.dev or [ext] subjectAltName = DNS:api.dev,DNS:*.api.dev

https://github.com/bscheshirwork/docker-yii2-app-advanced-rbac/blame/api/docs/about-api-ssl.md#L113

connect to server use IP of host machine and verify by hostHeader, not by host

const char* host = "192.168.1.39";
const char* hostHeader = "api.dev";
const int httpsPort = 8082;
String url = "/v1/feedback/create";
// Use web browser to view and copy SHA1 fingerprint of the certificate or use
// openssl x509 -in server.crt -fingerprint 
const char* fingerprint = "A1 1F 18 32 A7 2C CE 2B 74 F8 0E 35 A7 11 16 11 7F 61 22 C9";
...
setup(){
...
  //connect to host
  Serial.print("connecting to ");
  Serial.println((String)host);
  if (!espClient.connect(host, httpsPort)) {
    Serial.println("connection failed");
    return;
  }


  if (espClient.verify(fingerprint, hostHeader)) {
    Serial.println("certificate matches");
  } else {
    Serial.println("certificate doesn't match");
  }
  
  Serial.print("requesting URL: ");
  Serial.println(url);

  espClient.print(String("POST ") + url + " HTTP/1.1\r\n" +
               "Host: " + hostHeader + "\r\n" +
               "User-Agent: MP3ESP8266\r\n" +
               "Connection: close\r\n\r\n");

}

https://github.com/bscheshir/esp8266-mp3-web-server/blob/b1f0231c3f8681c39d040d99b39d200282ad1ab3/WiFiWebServerMP3.ino#L40-L46
https://github.com/bscheshir/esp8266-mp3-web-server/blob/b1f0231c3f8681c39d040d99b39d200282ad1ab3/WiFiWebServerMP3.ino#L185-L206

I think about use your library, but
in this library I can see only equials sslClient.verify(...,host) ; sslClient.connect(host,...)

if(!sslClient.connect(host, port)){
HTTP_DEBUG_PRINT("HTTPS Connection failed\n");
return 0;
}
if (fingerprint) {
HTTP_DEBUG_PRINT("Verifiying SSL certificate\n");
if (sslClient.verify(fingerprint, host)) {

RestClient.cpp: error: 'class BearSSL::WiFiClientSecure' has no member named 'verify' (when compiling with esp8266 3.0.1)

  • Installed latest Arduino IDE 1.8.15 on Windows 10
  • Installed latest esp8266 3.0.1 via https://arduino.esp8266.com/stable/package_esp8266com_index.json
  • Selected "LOLIN(WEMOS) D1 R2 & mini" board type
  • Copied RestClient[.cpp,.h] into examples/simple_POST
  • Opened simple_Post.ino and attempted to compile. Generates the following error:
C:\tmp\esp8266-restclient\examples\simple_POST\RestClient.cpp: In member function 'int RestClient::request(const char*, const char*, const char*, String*)':

C:\tmp\esp8266-restclient\examples\simple_POST\RestClient.cpp:167:27: error: 'class BearSSL::WiFiClientSecure' has no member named 'verify'

  167 |             if (sslClient.verify(fingerprint, host)) {
      |                           ^~~~~~

Default content type not set correctly

The following code put in RestClient constructor will not work (by default all member pointers have undefined values, not NULLs):

if (contentType == NULL) {
  contentType = "application/x-www-form-urlencoded";  // default
}

Working solution would be just getting rid of if clause:

contentType = "application/x-www-form-urlencoded";

Observed on WeMos whild sending POST requests.

Strange behaviour

Hi,

first, thanks for your work. I have a strange behaviuor using your RestClient library as a pointer.
I define a RestClient object as a pointer, because i need to create it after loading the collector host IP from a config file:

RestClient *restClient;

Later i initialize the object:

      ...
      restClient = new RestClient(config.collector_host); 
      ....

and i send data via POST like:

  char query[128];
  String response="";
  ...
          sprintf(query,"key=%s&ts=%d&t=%s&p=%s&h=%s&uv=%d&pm25=%s&pm10=%s",config.api_key,data.ts,data.temp,data.pres,data.hum,data.uv,data.pm25,data.pm10);
          statusCode = restClient->post("/rest/data/put", query, &response);

but watching data with tcpdump, i see strange behavour in header like:

POST /rest/data/put HTTP/1.1
Host: [host]:80
Connection: close
Content-Length: 36
**Content-Type: L.).**

key=KEY&t=21.60&h=39.80

Any help really appreciated !

Missing blank line when using POST

RestClient::request() adds a blank line between headers and request body if the method is GET, but this blank line is needed for other methods too, such as POST.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.