I am trying to send an HTTP Post to a channel I created on Thingspeak.com. I am using the provided code for the Keil environment and have tried multiple different things to try to post a value to my channel. Below is the configuration of the sendHttpPostDemo() function. The only modification I made was to change the content type from "text/html" to "application/x-www-form-urlencoded". When I run the application I type following
e (selects HTTP Post)
http://api.thingspeak.com (server)
/update (uri)
mykey&field1=90
I get the following message:
HTTP RSP code: 21, seq #13
When I look up the code this is decimal 21 which is 0x15. According to the SNIC Serial Interface manual this represents "SNIC_INVALID_ARGUMENT". There is no more detail regarding the invalid argument.
I am able to post values to Thingspeak using Mozilla HTTP Poster program. This appears to be something directly related to how the code is managing the request for the post. Any help would be appreciated.
sendHttpPostDemo Function that was slightly modified
int sendHttpPostDemo(char *domain)
{
cchar content[256]={0};
char tmp[100];
char method = 1; //POST
char contentType[] = "application/x-www-form-urlencoded"; // Was "text/html"
char otherHeader[] = "Accept-Language: en-US\r\n";
unsigned char timeout = 10;
printf("Enter URI after the server name: ([CR] to accept %s)\n\r", uri);
scanf("%s",tmp);
printf("\n\r");
if (strlen(tmp))
strcpy(uri, tmp);
printf("Enter content to POST: \n\r");
scanf("%s",content);
printf("\n\r");
if (strlen(uri)==0)
strcpy(uri, "/add.php");
return fillNSendHttpReq(seqNo++, domain, uri, method, contentType, otherHeader, strlen(content), content, timeout, 0,0);
}