Send a string to Agent via HTTP Request

I would like to send a email adress to my imp using a web browser.

I’m not really good with java or http, but I dont care If I have to send it by including the email adress in the agent link, or if my Agent create a web page with a text field and a button.

Does anybody know how to do so?

It would look something like this:

`// agent code
emailAddress <- null;

function requestHandler(req, resp) {
if (“email” in req.query) {
emailAddress = req.query[“email”];
}

// other http handler code
// ...

// send a response
resp.send(200, "OK");

}

http.onrequest(requestHandler);

function doSomethingWithEmailAddress() {
// if email address hasn’t been set, log an error message and return
if (emailAddress == null) {
server.log(“ERROR: emailAddress not set”);
return;
}

// at this point we've validated we have an email address
// note - we haven't checked that it's a valid email address

}`

Take a look at the agents section in our Getting Started Guide.

While that example demonstrates how to send very basic data (in this case, the state of an LED), you can use the example setup for passing any kind of data (including email addresses, credentials, state information, etc).

NOTE: The agent example in the Getting Started Guide isn’t the most secure way of doing things (and certainly not necessarily “best practice”) - but it is a good starting point, especially if you are unfamiliar with web dev.

Any Idea how to do the same with a web page created by the agent ( instead of using the url? )

thank

The easiest way would be to create an HTML page with a textbox / form that submits the email address to the agent’s URL. Take a look at the SnackBot agent code - it isn’t exactly what you’re looking for, but it should serve as good starting point :slight_smile: