本文整理汇总了C++中HTTPClient::getString方法的典型用法代码示例。如果您正苦于以下问题:C++ HTTPClient::getString方法的具体用法?C++ HTTPClient::getString怎么用?C++ HTTPClient::getString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HTTPClient
的用法示例。
在下文中一共展示了HTTPClient::getString方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
示例2: requestConfig
int requestConfig(bool save) {
int ret = -1;
HTTPClient http;
// configure url
sprintf(url, "http://%s:%d/iotconfig?mac=%s", iotSrv, iotPort, macStr);
http.begin(url); //HTTP
// start connection and send HTTP header
int httpCode = http.GET();
// httpCode will be negative on error
if(httpCode > 0) {
// HTTP header has been send and Server response header has been handled
// file found at server
if(httpCode == HTTP_CODE_OK) {
String payload = http.getString();
int paysize = payload.length() + 1;
char json[paysize];
payload.toCharArray(json, paysize);
StaticJsonBuffer<jsonSize> jsonBuffer;
JsonObject& root = jsonBuffer.parseObject(json);
// Test if parsing succeeds.
if (!root.success()) {
// parsing failed
return ret; // bail out
} else { // parsing successful, save file
ret = root["cfgversion"];
if (save==true) {
File configFile = SPIFFS.open(jsonFile, "w");
if (!configFile) {
ret = -1;
}
root.printTo(configFile);
configFile.close();
}
}
}
} else {
ret = -1;
}
http.end();
return ret;
}
示例3: getHTTPFile
String getHTTPFile(String url) {
HTTPClient http;
String payload;
// Serial << "Retriving HTTP: " << url << endl;
http.begin(url); //HTTP
int httpCode = http.GET();
if(httpCode > 0) {
if (DEBUG) Serial << F("[HTTP] GET... code:") << httpCode << endl;
if(httpCode == HTTP_CODE_OK) payload = http.getString();
} else {
if (DEBUG) Serial << F("[HTTP] GET... failed, error:") << http.errorToString(httpCode).c_str() << endl;
}
http.end();
return payload;
}
示例4: getThingSpeak
String ICACHE_FLASH_ATTR ThingSpeakClass::getThingSpeak(String talkBackID, String talkApiKey) //talkback message processing
{ //TalkBack Function from thingspeak
String pageLength;
String CommandString = "";
String HTMLResult;
bool GoodResult = false;
DebugPrintln("talkback checking...");
if (TalkBackEnabled == false) return "";
if (thingSpeakURL == "") return "";
if (WiFi.status() != WL_CONNECTED) return ""; //check to make sure we are connected...
String url = "/talkbacks/" + talkBackID + "/commands/execute?api_key=" + talkApiKey;
HTTPClient http;
http.begin("http://"+ thingSpeakURL + url);
int httpCode = http.GET();
// httpCode will be negative on error
if (httpCode > 0) {
// HTTP header has been send and Server response header has been handled
//DebugPrintln("[HTTP] GET... code: " + String(httpCode));
// file found at server
if (httpCode == HTTP_CODE_OK) {
CommandString = http.getString();
}
}
else {
DebugPrintln("[HTTP] GET... failed, error: " + http.errorToString(httpCode));
}
http.end();
CommandString.replace("\n", "");
if (CommandString!="") DebugPrintln("Got talkback result : " + CommandString);
return CommandString;
}
示例5: loop
void loop() {
String url = "http://things.ubidots.com/api/v1.6/variables/" ID_VARIABLE "/values";
http.begin(url);
http.addHeader("Content-Type", "application/json");
http.addHeader("X-Auth-Token", AUTH_TOKEN);
int content_length =0;
String payload = String("{ \"value\": " + String(millis()/1000) + "}");
//content_length = payload.length();
//http.addHeader("Content-Length", String(content_length));
int httpCode = http.POST(payload);
if(httpCode > 0) {
String payload = http.getString();
Serial.println(payload);
}
else {
Serial.print("[HTTP] failed, error: ");Serial.println(http.errorToString(httpCode).c_str());
}
http.end();
delay(20000);
}
示例6: FinalizeConnection
bool SendMailSms::FinalizeConnection() {
HTTPClient http;
ESP.wdtDisable();
TRACE2("Open URL: ",m_Data);
if ( !http.begin(m_Data) ) {
TRACE2("Error opening URL: ",m_Data);
ESP.wdtEnable(10000);
return false;
}
int httpCode = http.GET();
TRACE2("HTTP Code: ",httpCode);
bool bRvl = false;
if (httpCode == HTTP_CODE_OK) {
String payload = http.getString();
TRACE(payload);
if (payload.indexOf("{\"success\":true")>=0) bRvl = true;
}
http.end();
ESP.wdtEnable(10000);
return bRvl;
}