文件路径(C:\Users\ ~~你的电脑名称~~ \AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.0\libraries\ESP8266HTTPClient\src)下
ESP8266HTTPClient.cpp中:
bool HTTPClient::sendHeader(const char * type)
{
if(!connected()) {
return false;
}
String header = String(type) + " " + (_uri.length() ? _uri : F("/")) + F(" HTTP/1.");
if(_useHTTP10) {
header += "0";
} else {
header += "1";
}
header += String(F("\r\nHost: ")) + _host;
if (_port != 80 && _port != 443)
{
header += ':';
header += String(_port);
}
header += String(F("\r\nUser-Agent: ")) + _userAgent +
F("\r\nConnection: ");
if(_reuse) {
header += F("keep-alive");
} else {
header += F("close");
}
header += "\r\n";
if(!_useHTTP10) {
header += F("Accept-Encoding: identity;q=1,chunked;q=0.1,*;q=0\r\n");
}
if(_base64Authorization.length()) {
_base64Authorization.replace("\n", "");
header += F("Authorization: Basic ");//大约在1121行
header += _base64Authorization;
header += "\r\n";
}
header += _headers + "\r\n";
Serial.printf("[HTTP-Client] sending request header\n-----\n%s-----\n", header.c_str());
return (_client->write((const uint8_t *) header.c_str(), header.length()) == header.length());
}
当HTTP请求时,需要加入 Authorization的请求头时会加多Basic导致出错,删除即可
header += F("Authorization: Basic ");//大约在源码1121行
不删除
GET http://ota.heclouds.com/ota/south/check?dev_id=****&manuf=101&model=10101&type=2&version=1 HTTP/1.1
User-Agent: Fiddler
Content-Type: application/json
Authorization: Basic version=2018-10-31&res=products%2F******&et=1561476160&method=sha1&sign=***********
Host: ota.heclouds.com
删除后
GET http://ota.heclouds.com/ota/south/check?dev_id=****&manuf=101&model=10101&type=2&version=1 HTTP/1.1
User-Agent: Fiddler
Content-Type: application/json
Authorization: version=2018-10-31&res=products%2F******&et=1561476160&method=sha1&sign=***********
Host: ota.heclouds.com
效果看倒数第二行 Authorization 字段
http.end();会清空之前获取的所有数据,请在处理完再调用
网友评论