BTW: The http api needs some in depth tutprials, this has a lot of potential and i think the wiki info and some forum posts are not enough.
This is a read-only snapshot of the ComputerCraft forums,
taken in April 2020.
HTTP Help
Started by RoD, 19 June 2014 - 05:09 PMPosted 19 June 2014 - 07:09 PM
Hey, i had tried the HTTP api in computercraft, it is working fine to websites like twitter, youtube and google. I need to connect to this website: http://textuploader.com and i can't…. I get nil response from the webstie. Anyone knows what's up?
BTW: The http api needs some in depth tutprials, this has a lot of potential and i think the wiki info and some forum posts are not enough.
BTW: The http api needs some in depth tutprials, this has a lot of potential and i think the wiki info and some forum posts are not enough.
Posted 19 June 2014 - 07:54 PM
I can connect to it without any issues. You should try again. Or perhaps it's a certain page you're having trouble with and not the actual site? It would help if you posted the exact URL you're connecting to.
Posted 19 June 2014 - 08:18 PM
I actually am trying to connect to the api page:
http://api.textuploader.com/v1
But i had tryed the main page as well:
http://textuploader.com/
Nothing…
BTW: Does it worth mention i am in ccemu..?
http://api.textuploader.com/v1
But i had tryed the main page as well:
http://textuploader.com/
Nothing…
BTW: Does it worth mention i am in ccemu..?
Edited on 19 June 2014 - 06:24 PM
Posted 19 June 2014 - 08:28 PM
Try it in minecraft.
Posted 19 June 2014 - 08:29 PM
Ah yes, I just tried it in the actual game. I was using cclite before. It seems that the site doesn't want connections from Java. To solve it, just pretend you're not connecting from Java by specifying a user agent.
local response = http.get("http://textuploader.com", { ["User-Agent"] = "YourProgramsNameOrSomethingThatIsntJava" })
print(response.readLine()) --# Should work now.
response.close()
Posted 19 June 2014 - 09:01 PM
Ah yes, I just tried it in the actual game. I was using cclite before. It seems that the site doesn't want connections from Java. To solve it, just pretend you're not connecting from Java by specifying a user agent.local response = http.get("http://textuploader.com", { ["User-Agent"] = "YourProgramsNameOrSomethingThatIsntJava" }) print(response.readLine()) --# Should work now. response.close()
Yup, it worked.
How did you know the problem was about java? Why this webstie and not google? And what are those arguments (User-Agent)? It seems usefull and i would like to learn mor about it. Sorry for so many question, i guess i am a curious person. Thanks :D/>
Edited on 19 June 2014 - 07:03 PM
Posted 19 June 2014 - 09:17 PM
Yup, it worked.
How did you know the problem was about java? Why this webstie and not google? And what are those arguments (User-Agent)? It seems usefull and i would like to learn mor about it. Sorry for so many question, i guess i am a curious person. Thanks :D/>
Some websites like to block connections from Java clients. I have no idea why they do this but they do.
User-Agent is a HTTP header, which tells a website what program the connection was established with (e.g. the browser). You can find a list of HTTP headers here.
Posted 19 June 2014 - 09:37 PM
Ok thnks :D/>Yup, it worked.
How did you know the problem was about java? Why this webstie and not google? And what are those arguments (User-Agent)? It seems usefull and i would like to learn mor about it. Sorry for so many question, i guess i am a curious person. Thanks :D/>
Some websites like to block connections from Java clients. I have no idea why they do this but they do.
User-Agent is a HTTP header, which tells a website what program the connection was established with (e.g. the browser). You can find a list of HTTP headers here.
Quick note: it wont work in ccemu. Maybe the version its too old? I guess i coul try to get the http api from a newest version of computercraft into the ccemu rom, but i guess the problem isn't in the http api…
Edit: I just realized there is no http api… lol stupid me XD
Edited on 19 June 2014 - 07:40 PM
Posted 19 June 2014 - 09:40 PM
Ok thnks :D/>
Quick note: it wont work in ccemu. Maybe the version its too old? I guess i coul try to get the http api from a newest version of computercraft into the ccemu rom, but i guess the problem isn't in the http api…
Yes, the HTTP API is probably too old. You should be using the new version of CCEmu, CCEmuRedux, anyway.
Edited on 19 June 2014 - 07:41 PM
Posted 19 June 2014 - 09:42 PM
Wow, thomas is making a new emulator? :D/> AwesomeOk thnks :D/>
Quick note: it wont work in ccemu. Maybe the version its too old? I guess i coul try to get the http api from a newest version of computercraft into the ccemu rom, but i guess the problem isn't in the http api…
Yes, the HTTP API is probably too old. You should be using the new version of CCEmu, CCEmuRedux, anyway.
Posted 20 June 2014 - 06:08 PM
Ok, i am having some troubles.
I want to connect to this page:
http://api.textuploader.com/v1/posts
In the browser it works, but when i try to do it in computercraft:
This one i get the same error as before (attempt to index ? (a nil value)):
I want to connect to this page:
http://api.textuploader.com/v1/posts
In the browser it works, but when i try to do it in computercraft:
This one i get the same error as before (attempt to index ? (a nil value)):
local response = http.get("http://api.textuploader.com/v1/posts", { ["User-Agent"] = shell.getRunningProgram() })
This one (wich is the one i want to use) just freeze (it loops):
local response = http.post("http://api.textuploader.com/v1/posts","X-TextUploader-API-Key:"..key, { ["User-Agent"] = shell.getRunningProgram() })
I want to get the response from the posts page and i can't get anything…Posted 20 June 2014 - 06:44 PM
The former will respond with 401 Unauthorised, which makes ComputerCraft return nil, so that's normal.
Anyway, the main issue lies in the latter piece of code:
The documentation says: "To identify yourself, you send the following HTTP header with your API key". Which means that the second argument you're passing has to be inside the header table.
Anyway, the main issue lies in the latter piece of code:
The documentation says: "To identify yourself, you send the following HTTP header with your API key". Which means that the second argument you're passing has to be inside the header table.
Edited on 20 June 2014 - 04:45 PM
Posted 20 June 2014 - 07:27 PM
For that i skip the second arument of the http.post and do something like:
?
local response = http.post("http://api.textuploader.com/v1/posts",_, { ["User-Agent"] = shell.getRunningProgram(), ["X-TextUploader-API-Key:"] = key })
?
Edited on 20 June 2014 - 05:27 PM
Posted 20 June 2014 - 07:34 PM
For that i skip the second arument of the http.post and do something like:local response = http.post("http://api.textuploader.com/v1/posts",_, { ["User-Agent"] = shell.getRunningProgram(), ["X-TextUploader-API-Key:"] = key })
?
You don't need a colon here:
["X-TextUploader-API-Key:"]
The second argument is required in http.post, so you can't skip it. Since you don't need post data, just use http.get.Edited on 20 June 2014 - 05:34 PM
Posted 20 June 2014 - 07:58 PM
This one returns nil:For that i skip the second arument of the http.post and do something like:local response = http.post("http://api.textuploader.com/v1/posts",_, { ["User-Agent"] = shell.getRunningProgram(), ["X-TextUploader-API-Key:"] = key })
?
You don't need a colon here:The second argument is required in http.post, so you can't skip it. Since you don't need post data, just use http.get.["X-TextUploader-API-Key:"]
local response = http.get("http://api.textuploader.com/v1/posts", { ["User-Agent"] = shell.getRunningProgram(), ["X-TextUploader-API-Key"] = key })
Posted 20 June 2014 - 08:05 PM
Hmm, that should work. I don't have any experience with TextUploader, so I can't help you there, especially because ComputerCraft doesn't give you much detail about what exactly fails. I'm assuming it's the authorisation that fails (the api key in particular) and not the actual connection, so you should check the TextUploader docs to see if you're missing anything.This one returns nil:local response = http.get("http://api.textuploader.com/v1/posts", { ["User-Agent"] = shell.getRunningProgram(), ["X-TextUploader-API-Key"] = key })
Posted 20 June 2014 - 08:11 PM
But even that the authorization fails, shouldn't i get this page:
http://api.textuploader.com/v1/posts ?
http://api.textuploader.com/v1/posts ?
Posted 20 June 2014 - 08:21 PM
No, ComputerCraft returns nil when something doesn't respond with a 200 OK response.But even that the authorization fails, shouldn't i get this page:
http://api.textuploader.com/v1/posts ?
Posted 20 June 2014 - 08:35 PM
hum..No, ComputerCraft returns nil when something doesn't respond with a 200 OK response.But even that the authorization fails, shouldn't i get this page:
http://api.textuploader.com/v1/posts ?
Are this parameters required:
-H "Accept: application/json" \
-H "Content-Type: application/json" \
?
Edited on 20 June 2014 - 06:40 PM
Posted 20 June 2014 - 08:45 PM
No, they're not.hum..
Are this parameters required:
-H "Accept: application/json" \
-H "Content-Type: application/json" \
?
Posted 20 June 2014 - 09:20 PM
Pretty strange.No, they're not.hum..
Are this parameters required:
-H "Accept: application/json" \
-H "Content-Type: application/json" \
?
Thanks anyways, i learned a lot :D/>