Making a http POST request using Arduino

后端 未结 4 1340
深忆病人
深忆病人 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:24

    The original question is already answered, but just for reference for people passing by via Google; here is a more complete example how to post data to a webserver with an Arduino:

    IPAddress server(10,0,0,138);
    String PostData = "someDataToPost";
    
    if (client.connect(server, 80)) {
      client.println("POST /Api/AddParking/3 HTTP/1.1");
      client.println("Host: 10.0.0.138");
      client.println("User-Agent: Arduino/1.0");
      client.println("Connection: close");
      client.print("Content-Length: ");
      client.println(PostData.length());
      client.println();
      client.println(PostData);
    }
    

提交回复
热议问题