Go Down

Topic: an array within an HTML GET command (Read 1 time) previous topic - next topic

donde

I have an HTML line in a sketch:
client.println("GET /xml/current_obs/KVNY.xml HTTP/1.0");
I would like to put a array in for KVNY.

char* icao[]={"KVNY"};

setup() ...

loop() ...

client.println("GET /xml/current_obs/(icao[0].xml HTTP/1.0");

This addition compiles and uploads, but doesn't work.



zoomkat

You might need to do something like below to get your array into the string you want to send.

client.println("GET /xml/current_obs/" + (icao[0]) + ".xml HTTP/1.0";
Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   8)

donde

Thanks, but that did not work.  It just inserted the + (icao[0]) + to the output.
Got to think about some more.

zoomkat

Any particular reason why you want to use an array instead of a string?
Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   8)

Aeturnalus

You're using cstrings, not String objects - the easiest way to do what you want would be sprintf.

Code: [Select]

char icao[]="KVNY";
// ...

char buf[strlen(icao) + 40]; // About 45 characters of buffer space
sprintf(buf, "GET /xml/current_obs/%s.xml HTTP/1.0", icao);
client.println(buf);


If you use a String object, the + operator will concatenate strings for you.

Go Up