A HTTP Client for the mbed networking libraries, with PUT method
Fork of HTTPClient by
Revision 14:0463c8425d73, committed 2012-08-14
- Comitter:
- stevep
- Date:
- Tue Aug 14 11:54:13 2012 +0000
- Parent:
- 13:be61104f4e91
- Commit message:
- Add HTTP PUT method.
Changed in this revision
HTTPClient.cpp | Show annotated file Show diff for this revision Revisions of this file |
HTTPClient.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r be61104f4e91 -r 0463c8425d73 HTTPClient.cpp --- a/HTTPClient.cpp Sun Aug 05 16:12:10 2012 +0000 +++ b/HTTPClient.cpp Tue Aug 14 11:54:13 2012 +0000 @@ -82,6 +82,11 @@ return connect(url, HTTP_POST, (IHTTPDataOut*)&dataOut, pDataIn, timeout); } +HTTPResult HTTPClient::put(const char* url, const IHTTPDataOut& dataOut, IHTTPDataIn* pDataIn, int timeout /*= HTTP_CLIENT_DEFAULT_TIMEOUT*/) //Blocking +{ + return connect(url, HTTP_PUT, (IHTTPDataOut*)&dataOut, pDataIn, timeout); +} + int HTTPClient::getHTTPResponseCode() { return m_httpResponseCode; @@ -143,7 +148,7 @@ //Send request DBG("Sending request"); char buf[CHUNK_SIZE]; - const char* meth = (method==HTTP_GET)?"GET":(method==HTTP_POST)?"POST":""; + const char* meth = (method==HTTP_GET)?"GET":(method==HTTP_POST)?"POST":(method==HTTP_PUT)?"PUT":""; snprintf(buf, sizeof(buf), "%s %s HTTP/1.1\r\nHost: %s\r\n", meth, path, host); //Write request ret = send(buf); if(ret) @@ -157,7 +162,7 @@ //Send default headers DBG("Sending headers"); - if( (method == HTTP_POST) && (pDataOut != NULL) ) + if( (method == HTTP_POST || method == HTTP_PUT) && (pDataOut != NULL) ) { if( pDataOut->getIsChunked() ) { @@ -187,7 +192,7 @@ size_t trfLen; //Send data (if POST) - if( (method == HTTP_POST) && (pDataOut != NULL) ) + if( (method == HTTP_POST || method == HTTP_PUT) && (pDataOut != NULL) ) { DBG("Sending data"); while(true)
diff -r be61104f4e91 -r 0463c8425d73 HTTPClient.h --- a/HTTPClient.h Sun Aug 05 16:12:10 2012 +0000 +++ b/HTTPClient.h Tue Aug 14 11:54:13 2012 +0000 @@ -102,6 +102,16 @@ */ HTTPResult post(const char* url, const IHTTPDataOut& dataOut, IHTTPDataIn* pDataIn, int timeout = HTTP_CLIENT_DEFAULT_TIMEOUT); //Blocking + /** Execute a PUT request on the url + Blocks until completion + @param url : url on which to execute the request + @param dataOut : a IHTTPDataOut instance that contains the data that will be posted + @param pDataIn : pointer to an IHTTPDataIn instance that will collect the data returned by the request, can be NULL + @param timeout waiting timeout in ms (osWaitForever for blocking function, not recommended) + @return 0 on success, HTTP error (<0) on failure + */ + HTTPResult put(const char* url, const IHTTPDataOut& dataOut, IHTTPDataIn* pDataIn, int timeout = HTTP_CLIENT_DEFAULT_TIMEOUT); //Blocking + /** Get last request's HTTP response code @return The HTTP response code of the last request */ @@ -112,7 +122,8 @@ { HTTP_GET, HTTP_POST, - HTTP_HEAD + HTTP_HEAD, + HTTP_PUT }; HTTPResult connect(const char* url, HTTP_METH method, IHTTPDataOut* pDataOut, IHTTPDataIn* pDataIn, int timeout); //Execute request