Making a http POST request using Arduino

后端 未结 4 1338
深忆病人
深忆病人 2020-12-13 02:55

I am trying to post information to an API on a web project that I have created and hosted. I am not sure what the exact format is for the HTTP POST request. Every time I t

4条回答
  •  [愿得一人]
    2020-12-13 03:11

    Another option is using the HTTPClient.h (for the arduino IDE on adafruit's ESP32 feather), which handles https with no effort it seems. I'm including JSON payload also and can successfully send an IFTTT webhook.

      HTTPClient http;
      String url="https:///testurl";
      String jsondata=();
    
      http.begin(url); 
      http.addHeader("Content-Type", "Content-Type: application/json"); 
    
      int httpResponseCode = http.POST(jsondata); //Send the actual POST request
    
      if(httpResponseCode>0){
        String response = http.getString();  //Get the response to the request
        Serial.println(httpResponseCode);   //Print return code
        Serial.println(response);           //Print request answer
      } else {
        Serial.print("Error on sending POST: ");
        Serial.println(httpResponseCode);
    
        http.end();
    
     }
    

提交回复
热议问题