@@ -70,6 +70,8 @@ void sendRequest(int light, String cmd, String value) {
7070 request += light;
7171 request += " /state/" ;
7272
73+ String contentType = " application/json" ;
74+
7375 // make a string for the JSON command:
7476 String hueCmd = " {\" " + cmd;
7577 hueCmd += " \" :" ;
@@ -81,23 +83,11 @@ void sendRequest(int light, String cmd, String value) {
8183 Serial.print (" JSON command to server: " );
8284
8385 // make the PUT request to the hub:
84- httpClient.beginRequest ();
85- httpClient.put (request);
86- httpClient.sendHeader (" Content-Type" , " application/json" );
87- httpClient.sendHeader (" Content-Length" , hueCmd.length ());
88- httpClient.endRequest ();
89- httpClient.write ((const byte*)hueCmd.c_str (), hueCmd.length ());
86+ httpClient.put (request, contentType, hueCmd);
9087
91- // read the status code and content length of the response
88+ // read the status code and body of the response
9289 int statusCode = httpClient.responseStatusCode ();
93- int contentLength = httpClient.contentLength ();
94-
95- // read the response body
96- String response = " " ;
97- response.reserve (contentLength);
98- while (httpClient.available ()) {
99- response += (char )httpClient.read ();
100- }
90+ String response = httpClient.responseBody ();
10191
10292 Serial.println (hueCmd);
10393 Serial.print (" Status code from server: " );
0 commit comments