[Home] [Downloads] [Search] [Help/forum]

Gammon Forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Lua
. . -> [Subject]  LuaSocket and the POST method
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

LuaSocket and the POST method

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page


Posted by Xinael   (3 posts)  [Biography] bio
Date Wed 04 Mar 2009 01:34 AM (UTC)
Message
Hi! I'm trying to use the LuaSocket library with the POST method to automate some web-based stuff. Try as I might, though, I can't find a full example of code using the POST method with LuaSocket, so I'm only half-aware of what I need to be doing.

My method at the moment is to http.request() the page containing the form I want to submit. I use some patterns to get the data out of this form, so I know the variables I need to be submitting and their values, as well as the page to submit them.

The problem comes with actually forming the query. I know that there's a second, optional parameter to http.request() that allows me to send POST data, and that I can also use the full syntax to specify the POST method and what data to send, but I have no idea what format the data should be in, and what it should look like. Table? String? What?

I'm aware as well that I also need to be setting the content type and content length - but I've no idea what those values should be, nor how to find them out. Any help with that would be vastly appreciated.

The specific site I'm trying to automate, by the way, is www.topmudsites.com's voting page. You can see an example voting page here: http://www.topmudsites.com/vote-revelate.html

Thanks!
[Go to top] top

Posted by David Haley   USA  (3,881 posts)  [Biography] bio
Date Reply #1 on Wed 04 Mar 2009 05:17 PM (UTC)
Message
Quote:
The specific site I'm trying to automate, by the way, is www.topmudsites.com's voting page. You can see an example voting page here: http://www.topmudsites.com/vote-revelate.html

Isn't it highly against policy to automate votes like this?

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
[Go to top] top

Posted by David Haley   USA  (3,881 posts)  [Biography] bio
Date Reply #2 on Wed 04 Mar 2009 08:18 PM (UTC)
Message
It's worth noting that by trying to help a MUD by cheating the vote, you can actually really hurt it. If the vote site realizes that you're automating the process, it might cancel all votes for the MUD.

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
[Go to top] top

Posted by Xinael   (3 posts)  [Biography] bio
Date Reply #3 on Thu 05 Mar 2009 02:41 PM (UTC)

Amended on Thu 05 Mar 2009 02:43 PM (UTC) by Xinael

Message
Read the rules - there's nothing in there against using this sort of script to automate your voting. The rules prohibit faking multiple votes from the same person by using proxies or whatever and they also prohibit games from soliciting votes in any way except a vote button.

I'm an end user, and I'm going to vote for my MUD every time I can anyway - automating the process just means I can stop worrying about it. My intention would be to create a one-click, in-client voter that allows me to just run the script whenever I can vote again and be done with it. Scripts like this already exist and have done for a long time - I'm just looking to make one in Lua.

Creating a completely automatic, in-the-background voter would be possible this way, and someone could use this sort of thing for that, yeah. But it's not explicitly against the rules and even if it was, they'd have to set it up to do that themselves.
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #4 on Thu 05 Mar 2009 07:04 PM (UTC)
Message
Hmmm, well assuming this is all inside the rules, I personally haven't used luasocket to do POST data. However I am guessing that a Google for "http post" would give examples.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Xinael   (3 posts)  [Biography] bio
Date Reply #5 on Thu 05 Mar 2009 10:49 PM (UTC)
Message
Aaaahhh... all becomes clear. I actually had this script working long ago, but hadn't read up on the 301 Moved Permanently error and thought the script was failing when it wasn't.

Like all things in Lua, this is much more simple than it'd seem at first glance. All you need to do is give the POST data (as seen at the bottom of the example here http://developers.sun.com/mobility/midp/ttips/HTTPPost/) as the second argument to http.request - the library handles everything else for you. The same query from that site would look like:

http.request("www.mysite.com/login.jsp","userid=joe&password=guessme")

and this works just as expected.

My request was working absolutely fine, but the response given from the voting page is code 301 Moved Permanently, to forward the client on to the main site once their vote's been processed. Your vote works fine, and this 301 response is in essence a "vote recieved" response. Once you have that, you're golden.

So yeah, thanks for giving me a kick, Nick, and telling me to go and do my own dirty work ;)
[Go to top] 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.


8,393 views.

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at FutureQuest]