Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are
spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the
password reset link.
Due to spam on this forum, all posts now need moderator approval.
Entire forum
➜ MUSHclient
➜ Lua
➜ Having trouble getting a .json file using luasocket (inexperienced with this...)
Having trouble getting a .json file using luasocket (inexperienced with this...)
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| Rivius
(99 posts) Bio
|
Date
| Mon 20 Aug 2012 11:58 AM (UTC) Amended on Mon 20 Aug 2012 05:23 PM (UTC) by Rivius
|
Message
| I have been attempting to get the file: api.lusternia.com/characters.json using luasocket, but it would seem whenever I try, what gets downloaded says that the server does not recognize the request I am sending.
I believe it might have to do with what I am sending:
"GET api.lusternia.com/characters.json HTTP/1.0\r\n\r\n"
With the host being api.lusternia.com and the port being 80.
Is there something else I should be sending instead? I'm mostly following from a tutorial I've seen, so I'm very unfamiliar with this. I can download regular html files just fine off other sites using this method.
Edit:
A friend had told me that the following worked for them:
"GET "..file.." HTTP/1.1\r\nHost: "..host.."\r\nAccept: text/json\r\nUser-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:12.0) Gecko/20100101 Firefox/12.0\r\n\r\n"
On attempting this, I receive this error:
HTTP/1.1 400 Bad Request
Date: Mon, 20 Aug 2012 17:22:41 GMT
Server: Apache
Content-Length: 226
Connection: close
Content-Type: text/html; charset=iso-8859-1
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>400 Bad Request</title>
</head><body>
<h1>Bad Request</h1>
<p>Your browser sent a request that this server could not understand.<br />
</p>
</body></html>
Is there anything I can do about this? | Top |
|
Posted by
| Nick Gammon
Australia (23,133 posts) Bio
Forum Administrator |
Date
| Reply #1 on Tue 21 Aug 2012 01:43 AM (UTC) |
Message
| This seemed to pull in the page for me:
http = require "socket.http"
page, result = http.request "http://api.lusternia.com/characters.json"
print (page)
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Rivius
(99 posts) Bio
|
Date
| Reply #2 on Tue 21 Aug 2012 07:18 AM (UTC) |
Message
| Aye. I was attempting to avoid using http request since I could not make it non-blocking. After playing around quite a lot, this managed to work for me (and nothing less):
c:send("GET "..file.." HTTP/1.1\r\nUser-agent: "..socket._VERSION.."\r\nHost: "..host.."\r\nConnection: close\r\n\r\n")
I also had to change my receive function a bit because at the time I was using receive("*l"), but this was less than useful. Instead I simply went with receive(), but concatenated the third return value where appropriate.
thanks! | Top |
|
The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).
To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.
12,079 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top