Jump to content




How Do I Use Http Api Effectively


12 replies to this topic

#1 jay5476

  • Members
  • 289 posts

Posted 01 September 2013 - 03: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

#2 Zudo

  • Members
  • 800 posts
  • LocationUK

Posted 01 September 2013 - 04:00 AM

Please post your code.

#3 floppyjack

  • Members
  • 18 posts

Posted 01 September 2013 - 04:04 AM

Please also tell us what exactly you want to do.

#4 LBPHacker

  • Members
  • 766 posts
  • LocationBudapest, Hungary

Posted 01 September 2013 - 04: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:
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.

#5 Zudo

  • Members
  • 800 posts
  • LocationUK

Posted 01 September 2013 - 04:54 AM

View PostLBPHacker, on 01 September 2013 - 04:21 AM, said:

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.

#6 jay5476

  • Members
  • 289 posts

Posted 01 September 2013 - 04: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

#7 Yevano

  • Members
  • 376 posts
  • LocationUSA

Posted 01 September 2013 - 05:28 PM

View Postjay5476, on 01 September 2013 - 04:54 PM, said:

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.

#8 Imred Gemu

  • Members
  • 47 posts

Posted 01 September 2013 - 10:52 PM

View Postfloppyjack, on 01 September 2013 - 04:04 AM, said:

Please also tell us what exactly you want to do.
He wants to learn how the http api works

View PostZudoHackz, on 01 September 2013 - 04:54 AM, said:

View PostLBPHacker, on 01 September 2013 - 04:21 AM, said:

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.
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.

#9 jay5476

  • Members
  • 289 posts

Posted 02 September 2013 - 12:34 AM

okay how would I do something like get the first 3 sites google gets for the search 'computer'

#10 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,462 posts

Posted 02 September 2013 - 12: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.

#11 jay5476

  • Members
  • 289 posts

Posted 02 September 2013 - 12: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

#12 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,462 posts

Posted 02 September 2013 - 12: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.

#13 jay5476

  • Members
  • 289 posts

Posted 02 September 2013 - 01:06 AM

okay thanks





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users