0

Few days ago i'm post question about nodeMcu POST request, can't find any solution i'm try next on:

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")

But this request respond me with 301 error

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

Any ideas? May be problem with header's? Postman execute request fine

gre_gor
  • 6,669
  • 9
  • 47
  • 52
once2go
  • 1,452
  • 1
  • 13
  • 21

2 Answers2

3

The server probably enforces a / at the end of the request URL path.

If you use the URL with an extra /, that the redirect response tries to redirect you, you shouldn't get a 301 response back.

/wifi/?temp=24&hum=12&alert
     ↑
     └ extra slash
gre_gor
  • 6,669
  • 9
  • 47
  • 52
1

Status 301 is not an error, everything from 200-399 is considered success. In the case of 301 there will be a location header, that you use to build the redirected URL. 301 is returned by the server in response to a given URL, the only thing you can do (besides using location to follow it) on the client is use a different URL.

Mark McGinty
  • 756
  • 7
  • 13