Getting json data from HTTP URL


to get data from http url I have wrote following method:

String DownloadJson(String url){
    String output;
    if(client.connect(host, serverPort)) {
        client.println("GET "+url+" HTTP/1.0");
        client.println("Host: " + host);
        client.printlnf("Content-Length: %d", 2);
        client.println("Content-Type: application/json");
        while(client.available()) {
            char c =;
            output = output + c;
    return output;

however in response I get additional info along with response
e.g. HTTP/1.1 200 OK Connection: close Date: Sat, 01 Feb 2020 10:46:47 GMT Content-Type: application/json; charset=utf-8 Server: Kestrel X-Content-Type-Options: nosniff X-XSS-Protection: 1; mode=block X-Frame-Options: SAMEORIGIN [7,9,10,11]

how do I skip the extra info and get only [7,9,10,11]


You just discard everything up to a known starting indicator (e.g. \r\n\r\n[)

do we have any particle library to skip those HTTP headers?

The headers are coming back from Kestral, your web server, you’d have to parse out the response yourself in that case. Options would include changing out Kestral with a true tcp/ip cleint. You could also write a proxy to go between raw port communication and http communication, allowing it to strp out the contents you don’t want before the response.

Honestly, it’s just a bit of string manipulation, if you don’t care about the side of the payload being returned to the device.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.