Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
tests/blocking/socket/HttpPostTest.cpp
- Committer:
- dan_ackme
- Date:
- 2014-08-11
- Revision:
- 0:836c9a6383e0
- Child:
- 1:5137ec8f4c45
File content as of revision 0:836c9a6383e0:
/* * Copyright 2014, ACKme Networks * All Rights Reserved. * * This is UNPUBLISHED PROPRIETARY SOURCE CODE of ACKme Networks; * the contents of this file may not be disclosed to third parties, copied * or duplicated in any form, in whole or in part, without the prior * written permission of ACKme Networks. */ #include "tests/Tests.h" #include "Wiconnect.h" #define TEST_SERVER_URL "http://www.posttestserver.com" #define CONTEXT_TYPE "text/plain" static WiconnectResult addPostData(Socket &socket); static WiconnectResult readResponse(Socket &socket); /*************************************************************************************************/ WiconnectResult socketHttpPostCommand(int argc, char **argv) { WiconnectResult result; Wiconnect *wiconnect = Wiconnect::getInstance(); Socket socket(0, NULL, sizeof(testBuffer), testBuffer); uint32_t status; if(WICONNECT_FAILED(result, wiconnect->httpPost(socket, TEST_SERVER_URL, CONTEXT_TYPE))) { LOG_ERROR("Failed to open POST connection"); } else if(WICONNECT_FAILED(result, addPostData(socket))) { LOG_ERROR("Failed to add POST data"); } else if(WICONNECT_FAILED(result, wiconnect->httpGetStatus(socket, &status))) { LOG_ERROR("Failed to read HTTP status"); } else if(WICONNECT_FAILED(result, readResponse(socket))) { LOG_ERROR("Failed to read POST response"); } return result; } /*************************************************************************************************/ static WiconnectResult addPostData(Socket &socket) { WiconnectResult result; LOG_INFO("Enter post data ('\\n' issues request):"); int c; for(;;) { c = consoleSerial.getc(); consoleSerial.putc(c); if(c == '\r') continue; if(c == '\n') break; if(WICONNECT_FAILED(result, socket.putc(c))) { return result; } } return socket.flushTxBuffer(); } /*************************************************************************************************/ static WiconnectResult readResponse(Socket &socket) { uint8_t *buffer; uint16_t size; LOG_INFO("Response data:"); while(socket.read(&buffer, &size) == WICONNECT_SUCCESS) { logWrite(buffer, size); } return WICONNECT_SUCCESS; }