当前位置: 首页>>代码示例>>C++>>正文


C++ HTTPClient::getString方法代码示例

本文整理汇总了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;
}
开发者ID:Rikkweb,项目名称:LibTeleinfo,代码行数:41,代码来源:webclient.cpp

示例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;
}
开发者ID:gordonthree,项目名称:multiswitch,代码行数:49,代码来源:multiswitch.cpp

示例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;
}
开发者ID:vlast3k,项目名称:vThingCO2,代码行数:16,代码来源:OTA.cpp

示例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;
	
}
开发者ID:nailbuster,项目名称:EspressModuleHM,代码行数:43,代码来源:ThingSpeak.cpp

示例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);
}
开发者ID:unloquer,项目名称:postUbidots,代码行数:20,代码来源:main.cpp

示例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; 
}
开发者ID:binhpham1909,项目名称:Arduino,代码行数:22,代码来源:SendEmailSms.cpp


注:本文中的HTTPClient::getString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。