Attempting to POST data with HttpClient.
Dependencies: EthernetInterface HTTPClient mbed-rtos mbed
Fork of HTTPClient_HelloWorld by
main.cpp
- Committer:
- terrence
- Date:
- 2015-03-18
- Revision:
- 3:64b3aa4b90f1
- Parent:
- 2:270e2d0bb85a
File content as of revision 3:64b3aa4b90f1:
//find httpclient-ssl by mason. #include "mbed.h" #include "EthernetInterface.h" #include "HTTPClient.h" EthernetInterface eth; HTTPClient http; char str[512]; char json[125]; int main() { // HTTPText text("text/html", bufsiz); //HttpText(const string& encoding = "text/html") // printf("(Buffer size of a HTTPText : %d)\n", bufsiz); // HTTPResult r = client.get(url, &text); //'{\"Email\":\"tps@tps.com\",\"PhoneNumber\":\"512-244-6688\",\"RowKey\":\"20141122:105633\",\"PartitionKey\":\"spencer\"}' //strcpy(str, "This is a PUT test!"); //HTTPText outText(str); eth.init(); //Use DHCP eth.connect(); printf("IP Address is %s\n", eth.getIPAddress()); //POST data HTTPMap map; map.put("value", "World"); http.setDataType("Content-Type","application/x-www-form-urlencoded"); http.setRequestHeader("Content-Length",210); string data = "={\"PartitionKey\":\"LSlaughter\",\"RowKey\":\"20150318:111818\",\"SubLocationID\":\"600W8thOffice\"}"; HTTPText jsonText("value"); jsonText.set(data); printf("\nTrying to post data...\r\n"); int ret = http.post("http://tpswebapi1.azurewebsites.net/api/values", jsonText, null); if (!ret) { printf("Executed POST successfully - read %d characters\r\n", strlen(str)); printf("Result: %s\r\n", str); } else { printf("Error - ret = %d - HTTP return code = %d\r\n", ret, http.getHTTPResponseCode()); } eth.disconnect(); while(1) { } }