Hi.
I’ve been trying to use TCPClient.read() to get the data from WEB server,but not work.
Clent:
TCPClient client;
byte server[] = { xx, xx, xx, xx};
void setup() {
Serial.begin(9600);
while(!Serial.available()) Particle.process();
if (client.connect(server, 80))
{
client.println("POST /xxxxxxxx.php HTTP/1.0");
client.println("Host:www.xxxxxx.xxxxxx");
client.println("Content-Type: application/x-www-form-urlencoded");
client.println("Content-Length:54");
client.println();
client.println("action=Sensor&Latitude=35.000000&Longitude=135.000000");
client.println();
}
else
{
Serial.println("connection failed");
}
}
void loop() {
int n = client.available();
if (n)
{
for( int i =0; i < n; i ++ )
{
char c = client.read();
Serial.print(c);
}
}
}
When server side php code:
<?php
require_once "HTTP/Request.php";
print('abcdefghijklmnopqrstuvwxyz');
print('ABCDEFGHIJKLMNOPQRSTUVWXYZ');
print('abcdefghijklmnopqrstuvwxyz');
print('ABCDEFGHIJKLMNOPQRSTUVWXYZ');
print('12');
?>
Result:
HTTP/1.1 200 OK
Date: Sat, 12 Mar 2016 04:00:41 GMT
Server: Apache/2.2.31
X-Powered-By: PHP/5.2.17
Connection: close
Conten
…Short.
When server side php code:
<?php
require_once "HTTP/Request.php";
print('abcdefghijklmnopqrstuvwxyz');
print('ABCDEFGHIJKLMNOPQRSTUVWXYZ');
print('abcdefghijklmnopqrstuvwxyz');
print('ABCDEFGHIJKLMNOPQRSTUVWXYZ');
print('123')
?>
Result:
HTTP/1.1 200 OK
Date: Sat, 12 Mar 2016 04:03:37 GMT
Server: Apache/2.2.31
X-Powered-By: PHP/5.2.17
Connection: close
Content-Type: text/html
abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123
…OK.
When server side php code:
<?php
require_once "HTTP/Request.php";
print('abcdefghijklmnopqrstuvwxyz');
print('ABCDEFGHIJKLMNOPQRSTUVWXYZ');
print('abcdefghijklmnopqrstuvwxyz');
print('ABCDEFGHIJKLMNOPQRSTUVWXYZ');
print('1234')
?>
Result:
HTTP/1.1 200 OK
Date: Sat, 12 Mar 2016 04:06:20 GMT
Server: Apache/2.2.31
X-Powered-By: PHP/5.2.17
Connection: close
Content-Type: text/html
abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123
…Short.
When server side php code:
<?php
require_once "HTTP/Request.php";
?>
Result:
HTTP/1.1 200 OK
Date: Sat, 12 Mar 2016 04:12:12 GMT
Server: Apache/2.2.31
X-Powered-By: PHP/5.2.17
Content-Length: 0
Connec
…Short.
What am I doing wrong?