Unable to get data from http server


I wrote following sample firmware to get data from server,

if I directly hit the URL I get the data

however it does not return any data in firmware code

TCPClient client;

String host = "toptalkback.com";
const int serverPort = 80;

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 = client.read();
            output = output + c;
    return output;

void setup() {


void loop() {
    String strHours = DownloadJson("/api/services/app/Septic/GetSchedule?serial=4c0030001851373237343331");
    Particle.publish("arr", strHours);

help appreciated


What does your code do?
Do you get nothing at all or just not the data you expect?
Your header indicates a 2 byte content, but where is it sent?

BTW, your response data when hitting the endpoint with a web browser is not valid JSON. Try a different content type.

downloads string from http url

I was getting null value

removed that line and it worked well

1 Like

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