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


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

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


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

示例1: submitData

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();
*/
}
开发者ID:CodeforChemnitz,项目名称:sensor_node-module-esp8266,代码行数:59,代码来源:rpc.cpp

示例2: 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


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