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


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

本文整理汇总了C++中HTTPClient::collectHeaders方法的典型用法代码示例。如果您正苦于以下问题:C++ HTTPClient::collectHeaders方法的具体用法?C++ HTTPClient::collectHeaders怎么用?C++ HTTPClient::collectHeaders使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在HTTPClient的用法示例。


在下文中一共展示了HTTPClient::collectHeaders方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: 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();

  }
开发者ID:vlast3k,项目名称:vThingCO2,代码行数:13,代码来源:TimerManager.cpp

示例2: updateTime

void TimeClient::updateTime() {
  HTTPClient http;

  String url = "http://www.google.com/";
  const char * headerkeys[] = {"Date"} ;
  size_t headerkeyssize = sizeof(headerkeys)/sizeof(char*);
  // Based on Arduino core BasicHttpClient.ino example
  // https://github.com/esp8266/Arduino/blob/1588b45a8a15e4d3f1b42f052fc41590e9bec0bb/libraries/ESP8266HTTPClient/examples/BasicHttpClient/BasicHttpClient.ino
  // configure http client and url
  http.begin(url); //HTTP
  http.collectHeaders(headerkeys,headerkeyssize);
  // 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
	  USE_SERIAL.printf("[HTTP] GET... code: %d\n", httpCode);
	  // file found at server
	  if ((httpCode == HTTP_CODE_OK)|| (httpCode == HTTP_CODE_FOUND)) {
		String payload = http.header("Date");
		USE_SERIAL.println(payload);
		http.end();
        payload.toUpperCase();
        // example:
      	// date: Thu, 19 Nov 2015 20:25:40 GMT
      	if (payload!=NULL) {
          Serial.println(payload.substring(17, 19) + ":" + payload.substring(20, 22) + ":" +payload.substring(23, 25));
          int parsedHours = payload.substring(17, 19).toInt();
          int parsedMinutes = payload.substring(20, 22).toInt();
          int parsedSeconds = payload.substring(23, 25).toInt();
          Serial.println(String(parsedHours) + ":" + String(parsedMinutes) + ":" + String(parsedSeconds));
          localEpoc = (parsedHours * 60 * 60 + parsedMinutes * 60 + parsedSeconds);
          Serial.println(localEpoc);
          localMillisAtUpdate = millis();
        }
      }
  }
}
开发者ID:kentaylor,项目名称:esp8266-weather-station,代码行数:38,代码来源:TimeClient.cpp


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