ja, funktioniert jetzt mit 2.5.2 (habe WiFi.config() momentan auskommentiert)
was ist passiert?
ja, funktioniert jetzt mit 2.5.2 (habe WiFi.config() momentan auskommentiert)
was ist passiert?
weiter oben lesen: https://www.roboternetz.de/community...l=1#post655595
- - - Aktualisiert - - -
@hawe
habe Deinen ersten Quelltext, nach den neuen Erkenntnissen, nochmals modifiziert:
Code:bool authorized=false; void handleNotAuthorized() { String readString = ""; char strinput[MAXLEN], strupwd[TOKLEN], struname[TOKLEN] ; WiFiClient client = wifiserver.available(); //--------------------------------------- // debug // authorized=true; strcpy(strinput, ""); strcpy(strupwd, ""); strcpy(struname, ""); while ( client.connected() ) { if (authorized) return; if ( client.available() ) { char c = client.read(); //read char by request readString = ""; while ( (readString.length() < TOKLEN) && (c != '\n') ) { readString += c; c = client.read(); } readString.toCharArray(strinput, MAXLEN); // cstringarg(strinput, "uname", struname); // uname // cstringarg(strinput, "upwd", strupwd); // upwd if(strstr(website_upwd,strupwd)!=NULL & strstr(website_uname,struname)!=NULL) { authorized = true; readString = ""; return; // return; // <<< selbes Ergebnis, egal ob kommentiert oder auskommentiert } //if HTTP request has ended if (c == '\n') { client.flush(); //now output html data header String script=""; script += ("<!DOCTYPE html> \n"); script += ("<html> \n"); script += ("<head> \n"); // utf-8 für "°" Zeichen script += "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"> \n" ; script += "<title>" ; script += "</title> \n" ; script += "</head> \n" ; script += "<body> \n" ; script += ("<h2><p style=\"color:rgb(255,0,191);\"> log in to proceed: </p> </h2> \n"); script += ("<FORM ACTION='/' method=GET > \n"); script += ("<h2>user name: <INPUT TYPE=text NAME='uname' VALUE='' MAXLENGTH='50'> </h2> \n"); script += ("<h2>password : <INPUT TYPE=PASSWORD NAME='upwd' VALUE='' MAXLENGTH='50'> </h2> \n"); script += ("<h2><INPUT TYPE=SUBMIT></h2> \n"); script += ("</FORM> \n"); script += ("<BR> \n"); script += ("</body> \n"); script += ("</html> \n"); //---------------------------------- String script1 = ""; script1 += ("HTTP/1.1 200 OK \n"); script1 += ("Content-Type: text/html \n"); script1 += ("Content-Length: ") + script.length() + ("\n"); script1 += ("\n"); // do not forget this one //???? script = script1+script; client.print(script); delay(100); //stopping client client.stop(); //clearing string for next read //readString = ""; } } delay(1); } }
äh, sorry, vor
// close the connection:
client.stop();
der "echte" ungekürzte Code ist dieser hier:
Code:void handleNotAuthorized() { String readString = ""; char strinput[MAXLEN], strupwd[TOKLEN], struname[TOKLEN] ; WiFiClient client = wifiserver.available(); strcpy(strinput, ""); strcpy(strupwd, ""); strcpy(struname, ""); while ( client.connected() ) { if (authorized) return; if ( client.available() ) { char c = client.read(); //read char by request readString = ""; while ( (readString.length() < TOKLEN) && (c != '\n') ) { readString += c; c = client.read(); } if(strstr(website_upwd,strupwd)!=NULL & strstr(website_uname,struname)!=NULL) readString.toCharArray(strinput, MAXLEN); // cstringarg( char* haystack, char* vname, char* sarg ) // haystack pattern: &varname=1234abc, delimiters &, \n, \0, SPACE, EOF cstringarg(strinput, "uname", struname); // uname cstringarg(strinput, "upwd", strupwd); // upwd // debug Serial.print("strupwd >>>"); Serial.print(strupwd); Serial.println("<<<"); Serial.print("website_upwd>>>"); Serial.print(website_upwd); Serial.println("<<<"); Serial.print("readString>>>");Serial.println(readString); if ( (strlen(strupwd)==strlen(website_upwd)) && (strcmp(website_upwd, strupwd)==0) && (strlen(struname)==strlen(website_uname)) && (strcmp(website_uname, struname)==0) ) { authorized = true; readString = ""; return; } //if HTTP request has ended if (c == '\n') { client.flush(); //now output html data header String script=""; script += ("<!DOCTYPE html> \n"); script += ("<html> \n"); script += ("<head> \n"); // utf-8 für "°" Zeichen script += "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"> \n" ; script += "<title>" ; script += "</title> \n" ; script += "</head> \n" ; script += "<body> \n" ; script += ("<h2><p style=\"color:rgb(255,0,191);\"> log in to proceed: </p> </h2> \n"); script += ("<FORM ACTION='/' method=GET > \n"); script += ("<h2>user name: <INPUT TYPE=text NAME='uname' VALUE='' MAXLENGTH='50'> </h2> \n"); script += ("<h2>password : <INPUT TYPE=PASSWORD NAME='upwd' VALUE='' MAXLENGTH='50'> </h2> \n"); script += ("<h2><INPUT TYPE=SUBMIT></h2> \n"); script += ("</FORM> \n"); script += ("<BR> \n"); script += ("</body> \n"); script += ("</html> \n"); //---------------------------------- String script1 = ""; script1 += "HTTP/1.1 200 OK \n"; script1 += "Content-Type: text/html \n"; script1 += "Content-Length: " + (String)script.length() + "\n"; script1 += "\n"; // do not forget this one //???? script = script1+script; client.print(script); delay(100); //stopping client /* while(client.connected()) { delay(10); } */ client.stop(); } } delay(1); } }
Warum so: (String)script.length()
bei mir funktionierte das auch ohne das "(String)"
???
PS: gib mal: "(String)" bei google ein, mit Gänsefüßchen oder ohne!![]()
![]()
bei mir ging es zunächst nicht, aber es stört jetzt auch nicht weiter![]()
Soll das (String) extra in String konvertieren?
ja, genau, habe es noch mal getestet und dann kommt ohne (String):
was ja eigentlich verständlich ist, denn lenghth() ist ja eine Zahl, die man nicht an cstrings addieren kann.ESP8266_ServerHomeWebMail_078:1273:59: error: invalid operands of types 'const char*' and 'const char [2]' to binary 'operator+'
script1 += "Content-Length: " + script.length() + "\n";
Lesezeichen