Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Can I post to http in Codea?

edited June 2013 in Questions Posts: 4

Is there some sort of way? For what I'm working on its important that I can. I know you can request things using http.request FYI

Tagged:

Comments

  • BortelsBortels Mod
    edited June 2013 Posts: 1,557

    Yup. Here's a function I use in some of my code, showing both the call and how to pass the POSTed data:


    function post(data, success, fail) if (sid) then data["sid"]=sid end local dstring = "" local k,v for k,v in pairs(data) do if (dstring == "") then dstring = k .. "=" .. v else dstring = dstring .. "&" .. k .. "=" .. v end end -- print(dstring) local t = { ["method"]="POST", ["data"]=dstring } http.request(url, success, fail, t) end

    To use, I'll do something like:

    post({["name"] = "Tom", ["age"] = "46", ["awesomeness"] = "the max"}, successfunction, failfunction)
    

    and set up appropriate functions to handle success or failure. (I think this is why http.get got renamed to http.request - it can do any method...)

  • edited June 2013 Posts: 129

    -nevermind-

  • Ohhhhhhh so http.request is post and get combined

    Now it makes sense

  • BortelsBortels Mod
    Posts: 1,557

    Yep. You can, in theory, override it with any of the http methods (DELETE, PUT, HEAD, etc), but I haven't tested that.

Sign In or Register to comment.