【问题标题】:Issue using HTTP POST/PUT through no-ip通过 no-ip 使用 HTTP POST/PUT 的问题
【发布时间】:2016-01-05 22:37:51
【问题描述】:

我有一个项目,我在家里通过 WAN 使用 Android 应用程序控制 Arduino。我正在使用麻省理工学院的 App Inventor 来设计应用程序,并使用 HTTP PUT/POST(我都尝试过)将信息字符串“helloThere”发送到 Arduino。直接向我的 IP 地址和端口号广播时,一切都很好。这是 Arduino 输出(我混淆了我的 IP 和端口):

PUT / HTTP/1.1
User-Agent: Dalvik/1.6.0 (Linux; U; Android 4.4.4; GT-I9305 Build/KTU84P)
Host: xx.xx.xx.xx:xxxx
Connection: Keep-Alive
Accept-Encoding: gzip
Content-Type: application/x-www-form-urlencoded
Content-Length: 10

helloThere

当我使用 DDNS(no-ip)来引用我的 IP 地址(因为它是动态的)时,就会出现问题。由于某种原因,PUT/POST 请求在通过此中继时不会执行。使用 DDNS 时 Arduino 的输出如下所示:

GET / HTTP/1.1
User-Agent: Dalvik/1.6.0 (Linux; U; Android 4.4.4; GT-I9305 Build/KTU84P)
Host: xx.xxx.xx.xx:xxxx
Connection: Keep-Alive
Accept-Encoding: gzip

不知何故,它正在更改为 GET 请求而不是 PUT/POST,但它仍在联系设备。老实说,我不是网络人,所以我对此感到很困惑,DDNS 不应该转发您发送给它的任何内容吗?我环顾四周,找不到任何关于此的内容,任何帮助或解释将不胜感激。

编辑:经过大量进一步研究后,我发现 DDNS 服务器在查询时实际上返回了所需主机名的 IP 地址。有谁知道没有 ip 使用什么地址和端口来执行此操作?我知道 Windows 使用“NSLOOKUP”来执行此操作,但我不知道这是如何在 arduino 上实现的。它可以通过 UDP 或 HTTP。再次感谢在这方面有经验的人提供的任何帮助。

【问题讨论】:

  • 好了,终于为有兴趣的朋友解决了这个问题。这是检索 ip 的 Arduino 代码:

标签: android html http arduino


【解决方案1】:

好的,终于为有兴趣的朋友解决了这个问题。这是检索 ip 的 Arduino 代码:

char server1[] = "xxxxxxxxxxxx.ddns.net"; //server to ping to get external
ip address
if (currentMillis - previousMillis >= interval) {
previousMillis = currentMillis;
if (client1.connect(server1, 80)) { // if you get a connection output to
serial:
  Serial.println("connected");
  client1.println("GET / HTTP/1.0");  //Make a HTTP request:
  client1.println("Host: xxxxxxxxxxxx.ddns.net");
  client1.println("Connection: close");
  client1.println();
  delay(1200);
}
while (client1.available()) { //loop to read html from external server and
take ip from it
  char c = client1.read();
  HTTPArray [counter] = c; // copy all the data from the buffer into an
array
  counter++;
}

【讨论】:

    猜你喜欢
    • 2011-01-02
    • 1970-01-01
    • 2013-11-11
    • 2012-03-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-29
    • 1970-01-01
    相关资源
    最近更新 更多