0

我有一个侦听端口 8733 的REST接口。我可以用Fiddler对其进行测试,它会回答。

我已经复制了 Fiddler 请求并将其放入带有以下程序的 Arduino 中。当我运行它时,我的 REST 接口没有被命中。我试图从另一台工作的 PC 上用 Fiddler 发送请求。所以没有防火墙问题。我还尝试向 Arduino 发送消息,它会收到它,因此连接没有问题。

我该如何解决这个问题?

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

// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,1,177);
IPAddress serverIP(192,168,1,39);
String serverIPString = "192.168.1.39";
int serverPort = 8733;
String ChargepointId = "";

// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
EthernetServer server(80);
boolean isProcessingCommand = false;
boolean isAvailableForCharging = false;
boolean isConnected = false;
String currentCommand = "";
String lastJsonMessage = "";

void setup() {
    // Open serial communications and wait for port to open:
     Serial.begin(9600);
      while (!Serial) {
       ; // Wait for serial port to connect. Needed for Leonardo only.
    }


    // Start the Ethernet connection and the server:
    Ethernet.begin(mac, ip);
    server.begin();
    Serial.print("server is at ");
    Serial.println(Ethernet.localIP());
}

void loop() {
    EthernetClient client;
    // If there's a successful connection:
    Serial.println("connecting...");
    if (client.connect(serverIP, 8733)) {
        if (client.available()) {
            client.println("PUT http://192.168.1.39:8733/Test_Time_Addresses/WebAPI.Services/ChargepointExternal/AcceptedConnection HTTP/1.1");
            client.println("Content-Type: application/json; charset=utf-8");
            client.println("Host: 192.168.1.39:8733");
            client.println("Content-Length: 56");
            client.println("Expect: 100-continue");
            client.println("Connection: Keep-Alive");
            client.println("");
            client.println("{\"ChargepointId\":\"e6bd0980-4c5b-4f76-955c-02a8269f44a9\"}");
            client.println("");
            delay(1000);
            Serial.println("DONE");
        }
    }
    else {
      // If you couldn't make a connection:
      Serial.println("connection failed");
      Serial.println();
      Serial.println("disconnecting.");
      client.stop();
    }
}
4

1 回答 1

1

这一行是错误的:

if (client.available()) {

无论如何,谢谢,对不起。

于 2013-07-01T21:20:48.250 回答