You might want to take a look at the source for the official ThingSpeak library for Arduino and base your source on it.
https://github.com/mathworks/thingspeak-arduino
Specifically, see this file:
https://github.com/mathworks/thingspeak-arduino/blob/master/src/ThingSpeak.h