Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- client.print(String("GET ") + path + " HTTP/1.1\r\n" + "Host: " + host + "\r\n" + "Connection: keep-alive\r\n\r\n");
- delay(500); // wait for server to respond
- // read response
- String section = "header";
- while(client.available()) {
- String line = client.readStringUntil('\r');
- Serial.print(line); // we’ll parse the HTML body here
- if (section=="header") { // headers..
- Serial.print(".");
- if (line=="\n") { // skips the empty space at the beginning
- section="json";
- }
- }
- else if (section=="json") { // print the good stuff
- section = "ignore";
- String result = line.substring(1); // Parse JSON
- int size = result.length() + 1;
- char json[size];
- result.toCharArray(json, size);
- StaticJsonBuffer<200> jsonBuffer;
- JsonObject& json_parsed = jsonBuffer.parseObject(json);
- if (!json_parsed.success()){
- Serial.println("parseObject() failed");
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement