Received special characters instead of right data from server

Hi everyone!

I use Arduino and ESP8266 for send and receive data with server. ESP8266 send(POST) data to server sucessfully. But when i use receice(GET) data (html,txt,xml...) from web server, My data are wrong. they are special characters.this problem takes me many days!
I can not understand!Please help me!
( My English is not good!)

This is code to read data from server:

String readData(long timeout)//const int timeout
{
  String response;
  char c ;
  unsigned long time = millis();
  while ( (time + timeout) > millis())
  {
    while (Serial1.available()>0)
    {
      // The esp has data so display its output to the serial window
     // response = response + char(esp.read());
      c =Serial1.read();
      Serial.write(c);//At this, printed special data
      response =response+ c; // read the next character.
      
    }
  }
  return response;
}

This is my screen when it prints:

GET /data.txt HTTP/1.1
Host: 192.168.1.11
Accept: "text/html,ap
SEND OK

+IPD,274:HTTP/1.1 200 OK
Date: Fri, 19 Jun 2015 08:10:58 GMT
Server: Apae4(n nL. /.1
tdi ,  58:G
g58e7
c-gbsone:
niceotptpnho

thank you!

What happen with me?? :frowning:

I have 2 files use the same way

  1. Can post data to server but not get data (getFromServer.ino)
  2. Cannot post data to server but get data ok (connect_bak.ion)

anybody helps me? Explain what happen with me?

Thank you very much!

getFromServer.ino (5.64 KB)

connect_bak.ino (2.89 KB)

With my node JS server I resolved that issue by setting the character encoding.
The piece of code I used in Node JS was:

socket.setEncoding('utf8');

So just find a way to set the character encoding to UTF8 or another type.