【问题标题】:GET request NodeMCU(ESP8266) 301 ErrorGET 请求 NodeMCU(ESP8266) 301 错误
【发布时间】:2020-03-31 12:18:06
【问题描述】:

几天前我发布了关于 nodeMcu POST 请求的问题,找不到任何解决方案,我接下来要尝试:

conn=net.createConnection(net.TCP, 0)
conn:on("receive", function(conn, payload) print(payload) end )
conn:on("connection", function(c)
conn:send("GET /wifi?temp=24&hum=12&alert HTTP/1.1\r\n"
.."Host: www.weatherman.bl.ee\r\n"
.."Cache-Control: no-cache\r\n"
.."Connection: keep-alive\r\nAccept: */*\r\n\r\n")
end)
conn:connect(80, "www.weatherman.bl.ee")

但是这个请求以 301 错误回复我

HTTP/1.1 301 Moved Permanently 
Date: Mon, 02 Nov 2015 20:03:50 GMT
Server: Apache
Location: http://www.weatherman.bl.ee/wifi/?temp=24&hum=12&alert
Content-Length: 270
Keep-Alive: timeout=2, max=100 
Connection: Keep-Alive
Content-Type: text/html; charset=iso-8859-1

有什么想法吗?可能是标题的问题? 邮递员执行请求很好

【问题讨论】:

  • 我尝试了相同的代码,它为我返回 Data saved succesfully。可能还有其他原因导致 301 重定向?
  • 节点 mcu 固件上的代码相同?如果是,请告诉我您的版本号,请
  • 不在nodemcu上;但是使用 luasocket 库的相同 lua 代码(和 curl 中的相同标头)。
  • 你应该接受正确的答案。

标签: .htaccess redirect esp8266 nodemcu


【解决方案1】:

服务器可能会在请求 URL 路径的末尾强制使用 /

如果您使用带有额外 / 的 URL,重定向响应会尝试重定向您,您不应收到 301 响应。

/wifi/?temp=24&hum=12&alert
     ↑
     └ extra slash

【讨论】:

    【解决方案2】:

    状态 301 不是错误,从 200 到 399 的所有内容都被视为成功。在 301 的情况下,将有一个位置标头,您可以使用它来构建重定向的 URL。 301 是服务器响应给定 URL 时返回的,您在客户端上唯一能做的(除了使用位置来跟踪它)就是使用不同的 URL。

    【讨论】:

      猜你喜欢
      • 2018-01-27
      • 1970-01-01
      • 2017-01-04
      • 2023-02-15
      • 2020-02-10
      • 1970-01-01
      • 1970-01-01
      • 2021-07-25
      • 1970-01-01
      相关资源
      最近更新 更多