从WiFiClient HTTPS请求示例开始,我试图使用其API从Github Gist获取一些代码,但是文件的某些部分丢失了
[...]
const char* host = "api.github.com";
const int httpsPort = 443;
String url = "/gists/0b3d5d67342c055cc9ba34b59d075da7";
// Use web browser to view and copy
// SHA1 fingerprint of the certificate
const char fingerprint[] PROGMEM = "59 74 61 88 13 CA 12 34 15 4D 11 0A C1 7F E6 67 07 69 42 F5";
void setup() {
Serial.begin(115200);
wifiSetup();
// Use WiFiClientSecure class to create TLS connection
WiFiClientSecure client;
Serial.print("Connecting to ");
Serial.println(host);
Serial.printf("Using fingerprint '%s'\n", fingerprint);
client.setFingerprint(fingerprint);
if (!client.connect(host, httpsPort)) {
Serial.println("Connection failed");
return;
}
Serial.print("Requesting URL: ");
Serial.println(url);
client.print(String("GET ") + url + " HTTP/1.1\r\n" +
"Host: " + host + "\r\n" +
"User-Agent: ESP8266\r\n" +
"Connection: close\r\n\r\n");
Serial.println("Request sent");
while (client.connected()) {
String line = client.readStringUntil('\n');
if (line == "\r") {
Serial.println("Headers received");
break;
}
}
String line = client.readStringUntil('\n');
line = line.substring(line.indexOf("content\":") + 10, line.indexOf("},") - 2);
Serial.println("Reply was:");
Serial.println("==========");
Serial.println(toHTML(line));
Serial.println("==========");
Serial.println("Setup end");
}
void loop() {
}
String toHTML(String source) {
Serial.print("toHTML length before/after: ");
Serial.print(source.length());
Serial.print("/");
source.replace("\\\\n", "==NEWLINE==");//Preserve document newlines
source.replace("\\n", "\n");//Replace newline
source.replace("==NEWLINE==", "\\n");
source.replace("\\\"", "\"");//Replace quotes
source.replace("\\t", "\t");//Replace tabs
Serial.println(source.length());
return source;
}
我要获取的文件:
[...]
function printDebugMap() {
map.forEach((value, key) => {
printDebug(`${key} = [${value}]`);
});
}
</script>
</head>
<body>
<h1 id="AppName">Spreadsheet Automatico</h1>
<form onsubmit="return doNameInput()">
<p>Nome giocatori:</p>
<input type="text" id="nameBox">
<input type="submit" value="Submit">
</form>
<hr/>
我实际上得到的是:跳过了一些文本
[...]
function printDebugMap() {
map.forEach((value, key) => {
printDebug(`${ype="text" id="nameBox">
<input type="submit" value="Submit">
</form>
<hr/>
当我添加一些随机无关的代码时,其中的一部分缺少部分更改,因此我不知道自己在做什么错