Sending http request to enter data into a google spreadsheet

I’m trying to send a simple http request, see example

http://script.google.com/macros/s/--PUB-SCRIPT-ID--/exec?col1=1&col2=‘pizza’

to enter data into a google spreadsheet following the code explained at http://stackoverflow.com/questions/16633154/how-to-post-to-google-docs-form-directly

When I enter the request into a browser it writes the data into the google table. When doing so in code the server answers with a Bad request. Any ideas?

if (client.connect("script.google.com", 80))
{
    client.println("POST /macros/s/--PUB-SCRIPT-ID--/exec?col1=23&col2=33  HTTP/1.1");
    client.println("Host: script.google.com");
    client.println("Connection: close");
    client.println();

    while (client.available()) //Read what is returned from the server
    {
        char c = client.read();
        if (millis() - lastSync > 500) continue; //Read for maximum 500ms, then continue
    }

    client.flush();
    client.stop();
}

Hi @Heavy,

Good question! There was a thread on this subject, and they came up with an example script that pulls data by running some javascript on Google Docs to pull data from the core:


(this script: http://pastebin.com/CeUfxw60)

There have also been some good threads on sending http POST and GET requests, here’s my goofy http get wrapper with basic auth: https://community.spark.io/t/doorbell-to-send-jsonrpc/2805 – It’s possible your POST request is failing for a lack of cookies and auth headers, but I’m not super familiar with the security requirements of posting to Google Docs :slight_smile:

Thanks,
David

Thank you, David!

Let me clarify the background of my question: I would like to send the request every time the spark core receives a PULSE by a water meter.

best
@Heavy