This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
etopsirhc's profile picture

http api post

Started by etopsirhc, 08 February 2013 - 01:36 PM
etopsirhc #1
Posted 08 February 2013 - 02:36 PM
how do you format a post for the http api?

what i'm trying to do is send some text to a php page
PixelToast #2
Posted 08 February 2013 - 02:49 PM
normally i dont use post, i usually use get because you can debug it through a standard browser
http://www.computerc.../HTTP_%28API%29
xuma202 #3
Posted 08 February 2013 - 02:59 PM
normally i dont use post, i usually use get because you can debug it through a standard browser
http://www.computerc.../HTTP_%28API%29

To debug POST requests you can use Postman for Google Chrome. (https://chrome.google.com/webstore/detail/postman-rest-client/fdmmgilgnpjigdojojpjoooidkmcomcm?utm_source=chrome-ntp-icon)

However sometimes you're forced to use POST parameters.

Back to topic:

Use this function http://computercraft.info/wiki/Http.post and layout the content of the postdata like so: "key=value&key2=value2" …
tesla1889 #4
Posted 08 February 2013 - 03:06 PM

if not http.post("www.websiteurl.com/script.php?v1="..textutils.urlEncode(value1).."&v2="..textutils.urlEncode(value2)) then
-- error code
end
or http.get. or http.request. still sends the data

just putting the pieces of what was already said together
etopsirhc #5
Posted 08 February 2013 - 05:20 PM
for what i'm doing i think i'll use xuma's method
though i may have to use tesla's later on
tesla1889 #6
Posted 08 February 2013 - 06:15 PM
something to consider is that HTTP documentation prefers the GET verb over the POST verb, so if you're only sending args in a URL, use http.get

their explanation is that GET is "safer" than POST

EDIT: HTTP documentation meaning IRL HTTP, not the API
remiX #7
Posted 08 February 2013 - 07:14 PM
I asked this question yesterday xD

Clicky!