0

上面的代码在 arduino 上的草图上运行。不知道是不是我设置的ip和服务器地址不对请大家帮忙!!!!!!

我在串行监视器上运行以运行代码。它说这是结果连接....连接失败

断开连接

#include <SPI.h>
#include <Ethernet.h>

byte mac[] = {   0x91, 0xA2, 0xEA, 0x0D, 0x2B, 0xB1 };
byte ip[] = {   196, 10, 10, 94};
byte server[] = { 196, 10, 10,63};

EthernetClient client;

void setup()
{

  Ethernet.begin(mac, ip);
  Serial.begin(9600);

  delay(1000);

  Serial.println("connecting...");

  if (client.connect(server,80)) {
    Serial.println("connected");
    client.print("GET http://196.10.10.63:89/calls/channel.php HTTP/1.0\n");
    client.print("Host: http://196.10.10.63:89");
    client.println();
  }
  else {
    Serial.println("connection failed");
  }
}

void loop()
{
  if (client.available()) {
    char c = client.read();
    Serial.print(c);
  }

  if (!client.connected()) {
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();
    for(;;)
      ;
  }
}
4

1 回答 1

0

您的代码提到从端口 89 获取页面:

client.print("GET http://196.10.10.63:89/calls/channel.php HTTP/1.0\n");

但你连接到端口 80:

if (client.connect(server,80)) {

如果正确,请将端口更改connect()为 89。同样在 GET 请求中,您不需要完整的 URL,请尝试路径:

client.print("GET /calls/channel.php HTTP/1.0\n");
client.print("Host: 196.10.10.63");
于 2013-10-16T17:16:24.520 回答