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.

donde

zoomcat!

Great help. I don't think I've seen sprintf in Arduino examples, but it surely is in C.

Thanks

PaulS

The information output for the GET command does not need to be output all at once.
Code: [Select]
client.print("GET /xml/current_obs/");
client.print(icao);
client.println(.xml HTTP/1.0");

will output the data in icao as part of the GET command, without the overhead of a buffer and the sprintf code.

Go Up