hi friends
i post a data length is 6...
get data length is 22...there is a space
with "data.trim();" functions is data length 12
How do I remove the top emptinesses
this space

my code
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
const char* ssid = "Kablonet_Netmaster-FAF6-G";
const char* password = "mortMen20122111";
void setup() {
Serial.begin(115200); // Start the serial monitor.
pinMode(2, OUTPUT); // Set GPIO2 as an OUTPUT.
digitalWrite(2, 0); // Start off.
WiFi.begin(ssid,password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
}
}
void loop() {
if (WiFi.status() == WL_CONNECTED) {
HTTPClient http;
http.begin("http://dislik.com/urun-lux-kasket-sapka-5"); // Request destination.
int httpCode = http.GET(); // Send the request.
if (httpCode > 0) { //Check the returning code
String data=http.getString();
Serial.println(data.length());
data.trim();
Serial.println(data.length());
Serial.println(data);
if (data=="0x0001")
{
digitalWrite(2,1);
}
else if (data=="0x0000")
{
digitalWrite(2,0);
}
else
{
Serial.println("Cihaz açık değil");
}
}else{
Serial.println("Something baaaaaaad happened!");
}
http.end(); //Close connection
}
delay(1000); //Send a request every 30 seconds
}
this space
https://imagizer.imageshack.com/img921/9200/r0AW2r.jpg
That's NOT a space. A space would be shown horizontally.
That is one or more carriage returns or line feeds.
trim() removes white space (spaces, carriage returns, line feeds, and tabs).
But, since you have NO idea what is actually in data, you have no way to know what trim() did, if anything.
Why do you insist on anonymous printing?
I don't see how your picture is related to your code. Follow the advice PaulS gave you in your other thread: print the received String between markers.
hi Paul
i send data is "0x0001"
Serial.println(data.length());
data.trim();
Serial.println(data.length());
Serial.println("[");
Serial.print(data);
Serial.println("]");
serial monitor
[
0x0001]
I want it that way
[0x0001]
but it does not
The trim() method is pretty specific in what it removes - spaces, tabs, carriage returns, and line feeds. Other non-printable characters are not removed.
Something in the process of getting the data must be putting some extra data in the server output that trim() does not remove.
Try this:
for(byte b=0; b<data.length(); b++)
{
Serial.print("data[");
Serial.print(b);
Serial.print("] = ");
Serial.println(data[b], HEX);
}
And lets see what trim() is not removing.
hi Paul
this serial monitor but get data length = 6 ?
data[0] = EF
data[1] = BB
data[2] = BF
data[3] = A
data[4] = A
data[5] = A
data[6] = 30
data[7] = 78
data[8] = 30
data[9] = 30
data[10] = 30
data[11] = 31
The length() function does NOT calculate the length of the string that the String instance wraps.
You are going to have to dig into the HTTPClient::getString() method to figure out why it is adding strange characters to the beginning of your data (unless you can determine that from Dislik.com is for sale | HugeDomains is doing) and why the value that it sets for the length of the String instance that it returns isn't reasonable.