Bonjour,
Je souhaite faire un sprintf mais sur plusieurs ligne car ca dépasse l'ecran.
J4ai essayé de plusieurs façon mais j'ai un warning.
warning: backslash and newline separated by space [-Wbackslash-newline-escape]
sprintf(tmp, "GET %s HTTP/1.1\r\nHost: %s\r\nAccept-Language: fr,fr-FR;q=0.8,en-US;q=0.5,en;q=0.3\r\n \
^
sprintf(tmp, "GET %s HTTP/1.1\r\nHost: %s\r\nAccept-Language: fr,fr-FR;q=0.8,en-US;q=0.5,en;q=0.3\r\n \
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8\r\n\r\n", path, ip);
ou
sprintf(tmp, "GET %s HTTP/1.1\r\nHost: %s\r\nAccept-Language: fr,fr-FR;q=0.8,en-US;q=0.5,en;q=0.3\r\n" \
"Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8\r\n\r\n", path, ip);
Merci.
kamill
February 2, 2024, 7:01am
2
Bonjour,
Comme ton deuxième exemple mais sans le backslash
sprintf(tmp, "GET %s HTTP/1.1\r\nHost: %s\r\nAccept-Language: fr,fr-FR;q=0.8,en-US;q=0.5,en;q=0.3\r\n"
"Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8\r\n\r\n", path, ip);
J-M-L
February 2, 2024, 7:49am
3
A noter que si c'est pour ensuite envoyer simplement sur le client, bâtir une chaîne en mémoire c'est du gâchis de SRAM...
faites simplement plusieurs print
client.print(F("GET "));
client.print(path);
client.print(F(" HTTP/1.1\r\nHost: "));
client.println(ip);
client.println(F("Accept-Language: fr,fr-FR;q=0.8,en-US;q=0.5,en;q=0.3"));
client.println(F("Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8"));
client.println();
ce sera aussi plus lisible
(si sur ESP8266 utilisez la macro F("") pour le texte, sur ESP32 ce n'est pas la peine)
andromeda92:
sprintf(tmp, "GET %s HTTP/1.1\r\nHost: %s\r\nAccept-Language: fr,fr-FR;q=0.8,en-US;q=0.5,en;q=0.3\r\n \
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8\r\n\r\n", path, ip);
Cette syntaxe fonctionne si le \ est le dernier caractère de la ligne. On doit avoir \ et saut ligne. C'est d'ailleurs ce qu'indique le warning. Dans la ligne en question il y a 5 tabulations après \
Merci pour ces informations et explications.
system
Closed
July 31, 2024, 8:01am
6
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.