在arduino客户端的php echo输出ghost char

I try to get a timeStamp from php page (http://www.honeyshare.cn/time.php) and use LinkIt ONE board which is Compatible with arduino as client.There is only one line code "echo time();" on php page.Then I get serial output like this

Connecting to AP
Connecting to WebSite
waiting HTTP response:
HTTP/1.1 200 OK
Date: Sun, 20 Dec 2015 09:17:26 GMT
Server: Apache
Vary: User-Agent,Accept-Encoding
Connection: close
Transfer-Encoding: chunked
Content-Type: text/html

7
1450605837
0

disconnected by server 

1450605837 is what I want.7 above this line and 0 below this line is ghost char.If I would not use echo and only write 1450605837 in php file as string, 7 or 0 will not show in the serial output.

Here is LinkIt ONE board code

#include <LTask.h>
#include <LWiFi.h>
#include <LWiFiClient.h>
#define WIFI_AP "XXXX"
#define WIFI_PASSWORD "XXXXX"
#define WIFI_AUTH LWIFI_WPA  // choose from LWIFI_OPEN, LWIFI_WPA, or LWIFI_WEP.
#define SITE_URL "www.honeyshare.cn"

LWiFiClient c;

void setup()
{
  LWiFi.begin();
  Serial.begin(115200);

  // keep retrying until connected to AP
  Serial.println("Connecting to AP");
  while (0 == LWiFi.connect(WIFI_AP, LWiFiLoginInfo(WIFI_AUTH, WIFI_PASSWORD)))
  {
    delay(1000);
  }

  // keep retrying until connected to website
  Serial.println("Connecting to WebSite");
  while (0 == c.connect(SITE_URL, 80))
  {
    Serial.println("Re-Connecting to WebSite");
    delay(1000);
  }

  // send HTTP request, ends with 2 CR/LF
//  Serial.println("send HTTP GET request");
  c.println("GET /time.php HTTP/1.1");
  c.println("Host: " SITE_URL);
  c.println("Connection: close");
  c.println();

  // waiting for server response
  Serial.println("waiting HTTP response:");
  while (!c.available())
  {
    delay(100);
  }
}

boolean disconnectedMsg = false;

void loop()
{
  // Make sure we are connected, and dump the response content to Serial
  while (c)
  {
    int v = c.read();
    if (v != -1)
    {
      Serial.print((char)v);
    }
    else
    {
      Serial.println("no more content, disconnect");
      c.stop();
      while (1)
      {
        delay(1);
      }
    }
  }

  if (!disconnectedMsg)
  {
    Serial.println("disconnected by server");
    disconnectedMsg = true;
  }
 delay(500);
}

Is there any idea about this problem? thx

douliangpo0128
douliangpo0128 非常感谢。
4 年多之前 回复
dongyao4419
dongyao4419 如果您不想解析它们,那么客户端使用HTTP1.0不允许服务器使用分块编码呢?
4 年多之前 回复
dqdes60666
dqdes60666 谢谢,我认为您编写的Chrome或小实用程序已自动解析HTTP1.1编码。
4 年多之前 回复
duanqiao1947
duanqiao1947 非常感谢。我相信“chunked”编码会产生额外的数字。可能是echotime();输出数字类型使长度为7?并且有任何想法将“1450605837”与所有文本分开?
4 年多之前 回复
dongxing4196
dongxing4196 c.println(“主持人:”SITE_URL);已验证。编译Consecuetive字符串文字,好像它们是一个字符串文字,其cintents是其内容连接的。
4 年多之前 回复
douxian3170
douxian3170 数字来自这一行:Serial.print((char)v);
4 年多之前 回复
douzhang2092
douzhang2092 我看不出它会有什么不同,因为我希望它能阻止编译。但是,c.println(“主持人:”SITE_URL);似乎对我怀疑,也许在SITE_URL之前有一个逗号丢失?使用Chrome中的开发工具和我写的一个小工具,我没有看到我收到的输出中的7或0。
4 年多之前 回复
dongyo7931
dongyo7931 我认为它们是在“chunked”编码中使用的长度,但奇怪的是长度为7而不是因为它们在1450605837中是10个字符。
4 年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐