This is a read-only snapshot of the ComputerCraft forums,
taken in April 2020.
How Do I Use Http Api Effectively
Started by jay5476, 01 September 2013 - 02:58 AMPosted 01 September 2013 - 04:58 AM
hi everybody any help is much appreciated, I want to know how I would use the http api effectively atm when I use http.get() I just get useless information
Posted 01 September 2013 - 05:00 AM
Please post your code.
Posted 01 September 2013 - 05:04 AM
Please also tell us what exactly you want to do.
Posted 01 September 2013 - 05:21 AM
What code. All he asked for is some advice on the HTTP API (though he could easily have found some on the Wiki). http.get (on success) returns a handle (that so called "useless information") which has two methods, .readAll and .close. readAll returns the response of the server, close closes the handle (it's highly advised to close the handle). Example:
Read the HTTP API documentation on the Wiki; there's a much cleaner explanation than this.
local handle = http.get("http://google.com") -- handle is not a string, it's the http handle
print(handle.readAll()) -- .readAll returns the actual response
handle.close()
Read the HTTP API documentation on the Wiki; there's a much cleaner explanation than this.
Posted 01 September 2013 - 05:54 AM
What code. All he asked for is some advice on the HTTP API (though he could easily have found some on the Wiki). http.get (on success) returns a handle (that so called "useless information") which has two methods, .readAll and .close. readAll returns the response of the server, close closes the handle (it's highly advised to close the handle). Example:local handle = http.get("http://google.com") -- handle is not a string, it's the http handle print(handle.readAll()) -- .readAll returns the actual response handle.close()
Read the HTTP API documentation on the Wiki; there's a much cleaner explanation than this.
I wanted to know how he was using it, so I could tell him what he was doing wrong.
Posted 01 September 2013 - 05:54 PM
okay I used your code bit, and got a bunch of information how would I use this like pastebin does to get information I could possibly use
Posted 01 September 2013 - 06:28 PM
okay I used your code bit, and got a bunch of information how would I use this like pastebin does to get information I could possibly use
Depends on what data you're trying to get and where you're getting it from. I'm guessing the "information" you get is HTML. Tell us what you're trying to do.
Posted 01 September 2013 - 11:52 PM
He wants to learn how the http api worksPlease also tell us what exactly you want to do.
He wasn't using it, he doesn't know how to use it, that's why he came here, to learn how to use it. You can only correct a mistake if someone makes one first, he never said he was having trouble with a program or that he had a program to begin with, he just wanted to learn how to use the api, presumably for programs that he might create in the future.What code. All he asked for is some advice on the HTTP API (though he could easily have found some on the Wiki). http.get (on success) returns a handle (that so called "useless information") which has two methods, .readAll and .close. readAll returns the response of the server, close closes the handle (it's highly advised to close the handle). Example:local handle = http.get("http://google.com") -- handle is not a string, it's the http handle print(handle.readAll()) -- .readAll returns the actual response handle.close()
Read the HTTP API documentation on the Wiki; there's a much cleaner explanation than this.
I wanted to know how he was using it, so I could tell him what he was doing wrong.
Posted 02 September 2013 - 01:34 AM
okay how would I do something like get the first 3 sites google gets for the search 'computer'
Posted 02 September 2013 - 01:36 AM
I believe Google blocks requests sent with a Java user agent, so you would be unable to do that. If you were able to do so with another site, you'd simply read through the returned page and pick out the relevant result URLs from the HMTL of the page.
Posted 02 September 2013 - 01:47 AM
so first I would have to read through what it returns where it returns and get it from that?
maybe if someone explained a bit how the 'pastebin program does it so efficently
maybe if someone explained a bit how the 'pastebin program does it so efficently
Posted 02 September 2013 - 01:59 AM
Pastebin provides a URL to get just the raw text of the paste, no HTML code. The pastebin program uses that to get just the text of the program, nothing else. Search engines do not usually provide comparable features.
Posted 02 September 2013 - 02:06 AM
okay thanks