ethernet shield+apache+php: client connect fails
hello everybody. have simple program call php file.
the .ino this:
the php code write "php correctly called" once it's called.
if run code many time resetting arduino obtain:
connecting...
connected
php correctly called
disconnecting.
connecting...
connection failed
disconnecting.
connecting...
connected
php correctly called
disconnecting.
connecting...
connected
php correctly called
disconnecting.
so, not "client.connect(server, 80)" return false...
if call many time php script browser have no problem suppose not server problem because apache answer correctly.
do have idea of why client connect fails?
thanks in advance help.
the .ino this:
code: [select]
"declaration...."
void setup() {
// start serial library:
serial.begin(9600);
// start ethernet connection:
if (ethernet.begin(mac) == 0) {
serial.println("failed configure ethernet using dhcp");
// no point in carrying on, nothing forevermore:
for(;;)
;
}
// give ethernet shield second initialize:
delay(2000);
serial.println("connecting...");
// if connection, report via serial:
if (client.connect(server, 80)) {
serial.println("connected");
// make http request:
client.println("get /myfile.php http/1.1");
client.println("user-agent: arduino");
client.println("accept: text/html");
client.println("connection: close");
client.println();
}
else {
// if didn't connection server:
serial.println("connection failed");
}
}
void loop()
{
// if there incoming bytes available
// server, read them , print them:
while (client.available()) {
char c = client.read();
serial.print(c);
}
// if server's disconnected, stop client:
if (!client.connected()) {
serial.println();
serial.println("disconnecting.");
client.stop();
// nothing forevermore:
for(;;)
;
}
}
the php code write "php correctly called" once it's called.
if run code many time resetting arduino obtain:
connecting...
connected
php correctly called
disconnecting.
connecting...
connection failed
disconnecting.
connecting...
connected
php correctly called
disconnecting.
connecting...
connected
php correctly called
disconnecting.
so, not "client.connect(server, 80)" return false...
if call many time php script browser have no problem suppose not server problem because apache answer correctly.
do have idea of why client connect fails?
thanks in advance help.
if server domain name, , not ip, should send "host" in header. see sent "connection: close", infers http/1.1. note change in send.
code: [select]
client.println("get /myfile.php http/1.1");
client.println("host: www.mydomain.com");
client.println("user-agent: arduino");
client.println("accept: text/html");
client.println("connection: close");
client.println();
Arduino Forum > Using Arduino > Networking, Protocols, and Devices (Moderator: fabioc84) > ethernet shield+apache+php: client connect fails
arduino
Comments
Post a Comment