Skip to content

Commit a632e15

Browse files
committed
added SimplePost
1 parent d501c6e commit a632e15

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

examples/SimplePost/SimplePost.ino

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#include <RestClient.h>
2+
#include <WiFi101.h>
3+
#include "config.h"
4+
5+
char serverAddress[] = "192.168.0.3"; // server address
6+
int port = 8080;
7+
8+
WiFiClient wifi;
9+
RestClient client = RestClient(wifi, serverAddress, port);
10+
int status = WL_IDLE_STATUS;
11+
String response;
12+
int statusCode = 0;
13+
14+
void setup() {
15+
Serial.begin(9600);
16+
while ( status != WL_CONNECTED) {
17+
Serial.print("Attempting to connect to Network named: ");
18+
Serial.println(ssid); // print the network name (SSID);
19+
20+
// Connect to WPA/WPA2 network:
21+
status = WiFi.begin(ssid, pass);
22+
}
23+
24+
// print the SSID of the network you're attached to:
25+
Serial.print("SSID: ");
26+
Serial.println(WiFi.SSID());
27+
28+
// print your WiFi shield's IP address:
29+
IPAddress ip = WiFi.localIP();
30+
Serial.print("IP Address: ");
31+
Serial.println(ip);
32+
}
33+
34+
void loop() {
35+
Serial.println("making POST request");
36+
String postData = "name=Alice&age=12";
37+
statusCode = client.post("/", postData);
38+
response = client.readResponse();
39+
Serial.print("Status code: ");
40+
Serial.println(statusCode);
41+
Serial.print("Response: ");
42+
Serial.println(response);
43+
44+
Serial.println("Wait five seconds");
45+
delay(5000);
46+
}

0 commit comments

Comments
 (0)