|
Having trouble getting a .json file using luasocket (inexperienced with this...)
|
Reply to this subject
Start a new subject
 
Refresh page
| Posted by |
Rivius
(93 posts) bio
|
| Date |
Mon 20 Aug 2012 11:58 AM (UTC) [ quote
] 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 (18,769 posts) bio
Forum Administrator |
| Date |
Reply #1 on Tue 21 Aug 2012 01:43 AM (UTC) [ quote
] |
| 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
(93 posts) bio
|
| Date |
Reply #2 on Tue 21 Aug 2012 07:18 AM (UTC) [ quote
] |
| 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.
808 views.
Reply to this subject
Start a new subject
 
Refresh page
top
Comments to:
Gammon Software support
Forum RSS feed ( http://www.gammon.com.au/rss/forum.xml )