Has anyone used http.request to post a webform? - SOLVED

The documentation suggests it is possible but isn’t clear, and I can’t get it to work. A simple example would help.

When I’ve posted directly to webforms in the past you usually have to make sure the headers are set correctly.

I haven’t done anything yet with codea and network access, but I suspect it’ll be where your problem lies.

Well, it was the headers, thank you, TechDojo, but it took quite a bit of trial and error to get it working. For the benefit of anyone who needs this in future, this works.

Replace the values of field1, field2 etc with the form field names, and value1, value2 etc with the values of those fields (NB don’t wrap them in quotes, & is the delimiter). So data might look like this:
data =“name=fred&score=125.4&comment=try harder”

Also replace URL in the request line at the end.

I’ve assumed you have two functions to deal with success and failure, called SubmitSuccess and SubmitFailure. Change as you wish.

    headers={}
    headers["Accept"]="text/plain"
    headers["Content-Type"]="application/x-www-form-urlencoded"
    headers["Accept-Charset"]="utf-8"
    data="field1="..value1.."&field2="..value2.."&field3="..value3"  --add more if you want
    http.request("URL",SubmitSuccess,SubmitFailure,{method="POST",
                         headers=headers,data=data})

Awesome Ignatz - I was stuck on this issue and your headers worked like a charm!

Thanks for that :slight_smile: