0

I am using the following command:

print(h.request([[http://www.amved.com/milindsweb/tableDB.html]]))

But all I get is this:

<!-- pageok -->
<!-- managed by puppet -->
<html>
<pre>pageok</pre>
</html>
200     table: 0092BD00 HTTP/1.1 200 OK

But the page as seen on a web browser has totally different content. How can I retrieve this page using http.request?

Thanks.

Milind
  • 415
  • 8
  • 24

1 Answers1

2

I don't see anything wrong with your code and I do get the expected result (the same as seen in the browser):

local h = require "socket.http"
local res, code, headers, status = 
  h.request([[http://www.amved.com/milindsweb/tableDB.html]])
print(#res, code, headers, status)

as expected returns:

45414   200 table: 0x00267e58   HTTP/1.1 200 OK

Perhaps you are going through some proxy server? You can also use something like wget or curl to compare the result you are getting on your machine with the one you are getting with your Lua script.

Paul Kulchenko
  • 25,884
  • 3
  • 38
  • 56
  • Thank you for your answer Paul. I checked again and I found some more information. If I use luasocket 2.0.2 then it works fine but if I use Lua 3.0 rc-1 then I get the wrong result. I think I will report to the luasocket github issues – Milind Jul 12 '14 at 21:32
  • Milind, I actually tested using "LuaSocket 3.0-rc1" (the one that is included with ZeroBrane Studio) and got the result above, which seems to be the correct one. – Paul Kulchenko Jul 12 '14 at 23:41
  • Hi Paul, as discussed in the Lua Mailing list the reason is that the luasocket 3.0 version I have is sending the host name and the port number in the host header. When I compared http.lua of Zerobranestudio and that from the luasocket github there are 2 additional lines on http.lua from github (212,213) which add the port number so that is why my copy was not working. – Milind Jul 16 '14 at 00:25
  • Milind, thank you for the clarification. I didn't realize that there were some changes in http.lua as I compiled using (what I thought was) 3.0rc1 version. – Paul Kulchenko Jul 16 '14 at 02:28