Twitter with OAuth Example.\\ see also http://www.soramimi.jp/twicpp/index.html

Dependencies:   mbed HTTPClient NTPClient_NetServices EthernetNetIf

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers oauth_http.cpp Source File

oauth_http.cpp

00001 /*
00002  * OAuth http functions in POSIX-C.
00003  *
00004  * Copyright 2007, 2008, 2009, 2010 Robin Gareus <robin@gareus.org>
00005  *
00006  * Permission is hereby granted, free of charge, to any person obtaining a copy
00007  * of this software and associated documentation files (the "Software"), to deal
00008  * in the Software without restriction, including without limitation the rights
00009  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00010  * copies of the Software, and to permit persons to whom the Software is
00011  * furnished to do so, subject to the following conditions:
00012  * 
00013  * The above copyright notice and this permission notice shall be included in
00014  * all copies or substantial portions of the Software.
00015  * 
00016  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00017  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00018  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00019  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00020  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00021  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00022  * THE SOFTWARE.
00023  *
00024  */
00025 #if HAVE_CONFIG_H
00026 # include <config.h>
00027 #endif
00028 
00029 #include <stdio.h>
00030 #include <stdarg.h>
00031 #include <stdlib.h>
00032 #include <string.h>
00033 
00034 #include "oauth.h"
00035 
00036 #include <HTTPClient.h>
00037 
00038 /* wrapper functions */
00039 
00040 /**
00041  * do a HTTP POST request, wait for it to finish 
00042  * and return the content of the reply.
00043  * (requires libcurl or a command-line HTTP client)
00044  *
00045  * more documentation in oauth.h
00046  *
00047  * @param u url to query
00048  * @param p postargs to send along with the HTTP request.
00049  * @return  In case of an error NULL is returned; otherwise a pointer to the
00050  * replied content from HTTP server. latter needs to be freed by caller.
00051  */
00052 std::string oauth_http_post(const char *u, const char *p)
00053 {
00054     HTTPClient http;
00055     HTTPText req("application/x-www-form-urlencoded");
00056     HTTPText res;
00057     req.set(p);
00058     http.post(u, req, &res);
00059     return res.get();
00060 }
00061