本文整理汇总了C++中HTTPClient类的典型用法代码示例。如果您正苦于以下问题:C++ HTTPClient类的具体用法?C++ HTTPClient怎么用?C++ HTTPClient使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了HTTPClient类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: while
void *HTTPClient::requestLoop(void *data)
{
HTTPClient * httpCli = (HTTPClient*)data;
while(1)
{
//Wait untill a new request is ready to be processed
httpCli->m_pRequestMutex->WaitForCond(COND_NEW_REQUEST);
if(true == httpCli->m_bShutdownRequestThread)
{
httpCli->m_pRequestMutex->Release();
break;
}
httpCli->SendRequest();
if(NULL != httpCli->extCallbackFunc)
{
httpCli->extCallbackFunc(httpCli->extDataPtr);
}
httpCli->m_pRequestMutex->Release();
httpCli->m_bRequestCompleted = true;
}
return NULL;
}
示例2: httpPost
/* ======================================================================
Function: httpPost
Purpose : Do a http post
Input : hostname
port
url
Output : true if received 200 OK
Comments: -
====================================================================== */
boolean httpPost(char * host, uint16_t port, char * url)
{
HTTPClient http;
bool ret = false;
unsigned long start = millis();
// configure traged server and url
http.begin(host, port, url);
//http.begin("http://emoncms.org/input/post.json?node=20&apikey=2f13e4608d411d20354485f72747de7b&json={PAPP:100}");
//http.begin("emoncms.org", 80, "/input/post.json?node=20&apikey=2f13e4608d411d20354485f72747de7b&json={}"); //HTTP
Debugf("http%s://%s:%d%s => ", port==443?"s":"", host, port, url);
// start connection and send HTTP header
int httpCode = http.GET();
if(httpCode) {
// HTTP header has been send and Server response header has been handled
Debug(httpCode);
Debug(" ");
// file found at server
if(httpCode == 200) {
String payload = http.getString();
Debug(payload);
ret = true;
}
} else {
DebugF("failed!");
}
Debugf(" in %d ms\r\n",millis()-start);
return ret;
}
示例3: main
int main(int argc, char *argv[])
{
string method, url, fileName, proxy;
if(argc==5){
method = argv[1];
url = argv[2];
fileName = argv[3];
proxy = argv[4];
}else{
cerr<<"Invalid number of parameters for starting HTTPClient"<<endl
<<"Usage: ./HTTPClientMain <method> <url> <localFileName> <direct/proxyaddress>"<<endl;
exit(-1);
}
HTTPClient* httpClient = new HTTPClient(method, url, fileName, proxy);
if(httpClient->run()){
cerr<<"Error in starting HTTPClient"<<endl;
exit(-1);
}
free(httpClient);
return 0;
}
示例4: connect
/********************************************************************
connect establishes a connection to the Slack RTM API
********************************************************************/
bool ArduinoSlackBot::connect() {
// Step 1: Find WebSocket address via RTM API (https://api.slack.com/methods/rtm.start)
HTTPClient http;
String slackAddr = "https://slack.com/api/rtm.start?token=";
slackAddr = String(slackAddr + slackToken);
PRINTLN(slackAddr);
http.begin(slackAddr.c_str(), slackSSLFingerprint);
int httpCode = http.GET();
if (httpCode != HTTP_CODE_OK) {
PRINTF("HTTP GET failed with code %d\n", httpCode);
return false;
}
WiFiClient *client = http.getStreamPtr();
client->find("wss:\\/\\/");
String host = client->readStringUntil('\\');
String path = client->readStringUntil('"');
path.replace("\\/", "/");
// Step 2: Open WebSocket connection and register event handler
PRINTLN("WebSocket Host=" + host + " Path=" + path);
webSocket.beginSSL(host, 443, path, "", "");
webSocket.onEvent(webSocketEvent);
return true;
}
示例5: getAPIHostnameOrDefault
void ArduRPC_SensorNode::submitData()
{
uint16_t i;
char hostname[NODE_EEPROM_API_HOSTNAME_MAX_LENGTH + 1];
uint16_t port;
if(this->status != 4) {
return;
}
if(WiFi.status() != WL_CONNECTED) {
return;
}
/*
if(connectSensorAPI() == false) {
return;
}
*/
getAPIHostnameOrDefault(&hostname[0], NODE_EEPROM_API_HOSTNAME_MAX_LENGTH);
port = getAPIPortOrDefault();
HTTPClient http;
String path;
path.reserve(64);
path = "/sensors/";
path += this->sensor_uuid;
http.begin(hostname, port, path);
http.addHeader("X-Sensor-Api-Key", this->sensor_key);
http.addHeader("X-Sensor-Version", "1");
int code;
code = http.POST(this->cache.data, this->cache.length);
NODE_DEBUG_PRINT("Code ");
NODE_DEBUG_PRINTLN(code);
// ToDo: validate code
this->status = 0;
/*
client.print("POST /sensors/");
client.println(this->sensor_uuid);
client.print("Host: ");
client.println(hostname);
client.println("Connection: close");
client.print("X-Sensor-Api-Key: ");
client.println(this->sensor_key);
client.println("X-Sensor-Version: 1");
client.print("Content-Length: ");
client.println(this->cache.length);
client.println();
for(i = 0; i < this->cache.length; i++) {
Serial.print((char)this->cache.data[i]);
}
this->status = 0;
client.stop();
*/
}
示例6: main
int main() {
MBED_HOSTTEST_TIMEOUT(15);
MBED_HOSTTEST_SELECT(default_auto);
MBED_HOSTTEST_DESCRIPTION(HTTP client hello world);
MBED_HOSTTEST_START("NET_7");
char http_request_buffer[BUFFER_SIZE + 1] = {0};
HTTPClient http;
EthernetInterface eth;
eth.init(); //Use DHCP
eth.connect();
//GET data
{
bool result = true;
const char *url_hello_txt = "http://developer.mbed.org/media/uploads/donatien/hello.txt";
printf("HTTP_GET: Trying to fetch page '%s'...\r\n", url_hello_txt);
HTTPResult ret = http.get(url_hello_txt, http_request_buffer, BUFFER_SIZE);
if (ret == HTTP_OK) {
printf("HTTP_GET: Read %d chars: '%s' ... [OK]\r\n", strlen(http_request_buffer), http_request_buffer);
} else {
printf("HTTP_GET: Error(%d). HTTP error(%d) ... [FAIL]\r\n", ret, http.getHTTPResponseCode());
result = false;
}
if (result == false) {
eth.disconnect();
MBED_HOSTTEST_RESULT(false);
}
}
//POST data
{
bool result = true;
const char *url_httpbin_post = "http://httpbin.org/post";
HTTPText text(http_request_buffer, BUFFER_SIZE);
HTTPMap map;
map.put("Hello", "World");
map.put("test", "1234");
printf("HTTP_POST: Trying to post data to '%s' ...\r\n", url_httpbin_post);
HTTPResult ret = http.post(url_httpbin_post, map, &text);
if (ret == HTTP_OK) {
printf("HTTP_POST: Read %d chars ... [OK]\r\n", strlen(http_request_buffer));
printf("HTTP_POST: %s\r\n", http_request_buffer);
} else {
printf("HTTP_GET: Error(%d). HTTP error(%d) ... [FAIL]\r\n", ret, http.getHTTPResponseCode());
result = false;
}
if (result == false) {
eth.disconnect();
MBED_HOSTTEST_RESULT(false);
}
}
eth.disconnect();
MBED_HOSTTEST_RESULT(true);
}
示例7: tcptask
static void tcptask(void* arg)
{
static uint16_t port = 30000;
HTTPClient* self = (HTTPClient*) arg;
TCPData tcpData;
for (;;) {
if (xQueueReceive(self->qHandle, &tcpData, 100)) {
port++;
struct netconn *conn = netconn_new(NETCONN_TCP);
err_t err;
if (conn != NULL) {
// Bind connection to the specified number
os_printf("Binding port %d\n", port);
err = netconn_bind(conn, NULL, port);
if (err == ERR_OK) {
struct ip_addr ip;
ip.addr = tcpData.serverIP;
os_printf("Connecting port %d\n", tcpData.serverPort);
err = netconn_connect (conn, &ip, tcpData.serverPort);
if (err == ERR_OK) {
os_printf("Writing data!\n");
netconn_write(conn, tcpData.data, TCP_DATA_SIZE, NETCONN_COPY);
struct netbuf *buf;
char *data;
u16_t len;
uint32_t offset = 0;
if ((buf = netconn_recv(conn)) != NULL) {
do {
netbuf_data(buf, (void**)&data, &len);
if (self->rxBuffer != NULL && data != NULL)
memcpy(self->rxBuffer + offset, data, len);
else
os_printf("HTTPClient::tcpTask self->rxBuffer or data is NULL!\n");
offset += len;
os_printf("Netconn received %d bytes\n", len);
} while (netbuf_next(buf) >= 0);
self->onReceive(tcpData.receiveCallback, tcpData.obj, self->rxBuffer);
netbuf_delete(buf);
}
}
}
}
netconn_close (conn );
netconn_delete (conn );
}
}
vTaskDelete(NULL);
}
示例8: main
int main(int argc, char *argv[])
{
HTTPClient client = HTTPClient(ENDPOINT, 8000);
client.GET();
printf("\nPress any key to exit...");
getchar();
return 0;
}
示例9: TestFindClientCertificate
// Test if we can find the MarlinClient certificate in my personal store
int TestFindClientCertificate()
{
HTTPClient client;
bool result = client.SetClientCertificateThumbprint("MY","db 34 40 64 f2 fa c2 13 18 dd 90 f5 07 fe 78 e8 1b 03 16 00");
// SUMMARY OF THE TEST
// --- "---------------------------------------------- - ------
printf("Can find the Marlin client certificate in store: %s\n",result ? "OK" : "ERROR");
return result ? 0 : 1;
}
示例10:
bool
StatisticsSender::SendStatistics(int iNoOfMessages) const
{
String sPage;
sPage.Format(_T("/statistics/update.php?hm_version=%s&hm_messages=%d"), Application::Instance()->GetVersionNumber(), iNoOfMessages);
AnsiString output;
HTTPClient Client;
return Client.ExecuteScript("www.hmailserver.com", sPage, output);
}
示例11: oauth_http_post
/**
* do a HTTP POST request, wait for it to finish
* and return the content of the reply.
* (requires libcurl or a command-line HTTP client)
*
* more documentation in oauth.h
*
* @param u url to query
* @param p postargs to send along with the HTTP request.
* @return In case of an error NULL is returned; otherwise a pointer to the
* replied content from HTTP server. latter needs to be freed by caller.
*/
std::string oauth_http_post(const char *u, const char *p)
{
HTTPClient http;
std::string strresult;
int numread = 0;
OAuthDataOut req("application/x-www-form-urlencoded", p);
OAuthDataIn res(result_buffer, RESULT_BUFFER_SIZ);
http.post(u, req, &res);
return res.getData();
}
示例12: httptest
int httptest(CellularModem& modem, const char* apn, const char* username, const char* password)
{
printf("Connecting...\n");
HTTPClient http;
char str[512];
modem.power(true);
Thread::wait(1000);
int ret = modem.connect(apn, username, password);
if(ret)
{
printf("Could not connect\n");
return false;
}
//GET data
printf("Trying to fetch page...\n");
ret = http.get("http://mbed.org/media/uploads/donatien/hello.txt", str, 128);
if (!ret)
{
printf("Page fetched successfully - read %d characters\n", strlen(str));
printf("Result: %s\n", str);
}
else
{
printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode());
modem.disconnect();
return false;
}
//POST data
HTTPMap map;
HTTPText text(str, 512);
map.put("Hello", "World");
map.put("test", "1234");
printf("Trying to post data...\n");
ret = http.post("http://httpbin.org/post", map, &text);
if (!ret)
{
printf("Executed POST successfully - read %d characters\n", strlen(str));
printf("Result: %s\n", str);
}
else
{
printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode());
modem.disconnect();
return false;
}
modem.disconnect();
return true;
}
示例13: Run
int StatsManager::Run(void *pv)
{
StatsManager* sm = reinterpret_cast<StatsManager*>(pv);
HTTPClient client;
while (sm->run_)
{
std::auto_ptr<Entry> entry;
{
ScopedMutex mutex(sm->entry_mutex_);
if (sm->entries_.empty())
{
sm->busy_ = false;
}
else
{
entry.reset(new Entry(sm->entries_.front()));
sm->entries_.pop();
}
}
if (entry.get())
{
entry->parameters["platform"] = A1_DISPLAY_PLATFORM;
if (dynamic_world->player_count > 1)
entry->parameters["session id"] = NetSessionIdentifier();
entry->parameters["username"] = network_preferences->metaserver_login;
entry->parameters["password"] = network_preferences->metaserver_password;
// generate checksum
uint32 checksum = 0;
for (std::map<std::string, std::string>::const_iterator it = entry->parameters.begin(); it != entry->parameters.end(); ++it)
{
checksum += checksum_string(it->first);
checksum += checksum_string(it->second);
}
std::ostringstream oss;
oss << checksum;
entry->parameters["checksum"] = oss.str();
client.Post(A1_STATSERVER_ADD_URL, entry->parameters);
}
else
{
SDL_Delay(200);
}
}
return 0;
}
示例14: getTimeFromGoogle
void getTimeFromGoogle(String &time) {
if (DEBUG) Serial << F("Check time from google") << endl;
if (waitForWifi(7000) != WL_CONNECTED) return;
HTTPClient http;
const char *headers[1] = {"Date"};
http.begin(F("http://google.com/"));
http.collectHeaders(headers, 1);
int rc = http.sendRequest("HEAD");
if (rc < 0) return;
time = http.header("Date");
//const char *d1 = http.header("Date").c_str();
}
示例15: fdev_get_udata
int
HTTPClient::clientWrite(char byte, FILE* stream)
{
if (stream == NULL)
{
return EOF;
}
http_stream_udata* udata = (http_stream_udata*) fdev_get_udata(stream);
HTTPClient* client = udata->client;
if (client->connected() == 0)
{
closeStream(stream);
return EOF;
}
if (udata->encode == 0)
{
client->write(byte);
if (client->debugCommunication)
{
Serial.print(byte);
}
}
else
{
if (URI_ALLOWED(byte) || ((URI_RESERVED(byte) && (udata->encode
& URI_ENCODE_RESERVED) == 0)))
{
client->write(byte);
if (client->debugCommunication)
{
Serial.print(byte);
}
}
else
{
char encoded[4] =
{ 0, 0, 0 };
sprintf(encoded, "%%%2x", byte);
// Write only the first three bytes, not the trailing null
for (char i = 0; i < 3; i++)
{
client->write(encoded[i]);
if (client->debugCommunication)
{
Serial.print(encoded[i]);
}
}
}
}
return 0;
}