Method Action Post using remote PHP script

Is it possible to post to a remote PhP script where arguments reside or perhaps call a webpage set up to automatically post by calling the webpage URL? Sort of like using a page redirect redirect code like such:

script language=“JavaScript” type="text/javascript"
var t = setTimeout(“document.myform.submit();”,100);
//2 seconds measured in miliseconds
/script

FORM name=“myform” ACTION=“http://URL/1/pm3/cgi/admin.cgi” method=post>
input name=action value=messanger type=hidden>
input name=from value=“admin” type=hidden>

TABLE BORDER=0 TR>
font color=#333333 face=verdana size=2>
INPUT type=text name=subject size=40 value=GSD>

font color=#333333 face=verdana size=2>b>To:/b>/font>
font face=verdana size=2> Attention Important!

font color=#333333 face=verdana size=2>
font face=verdana size=2>

INPUT TYPE=“radio” NAME=“by” VALUE=“email” CHECKED> e-mail

/TABLE>
Message
TEXTAREA rows=15 name=body cols=80 wrap=soft >

Message to be sent to users…

/TEXTAREA>

You can use HttpClient library to make a GET call, it can also make POST calls, but you need to format the body manually.

From the HttpClient example

request.hostname = "www.timeapi.org";
request.port = 80;
request.path = "/utc/now";

// The library also supports sending a body with your request:
//request.body = "{\"key\":\"value\"}";

// Get request
http.get(request, response, headers);
Serial.print("Application>\tResponse status: ");
Serial.println(response.status);

Serial.print("Application>\tHTTP Response Body: ");
Serial.println(response.body);

Thanks Mora, I’ve been successful at getting “Body” info from a webpage. I was wondering if it’s possible to call a page like opening it with a web browser where the code in the page can run the PHP script rather than posting it manually from the particle core. In the example the http://url.com/index.html has an auto page redirect which automatically posts the data for me. (Which I have set up an SMS mailto: Gateway to send group text messages) if an event is triggered. Right now I’m using C# program that I developed to make this call using an arduino and Xbee back to a PC which is running a program that detects the event, runs the args and calls the webpage where the group Text Messages are sent out. I’d like to remove the PC if at all possible and just have the Particle call the same page as the PC.

Yes, that’s called a GET request, which @MORA mentioned you could to with the referenced library. Have a look :slight_smile:

Well yes, the photon can call the page like a browser, but it wont execute the javascript there that makes the form submit, since theres not a real browser inside the photon or a javascript engine for that matter.

But PHP can send mails without using an external service, http://php.net/mail
You can also use IFTTT or Twillo, maybe together with the particle webhook system and get rid of both the PC and the PHP server :slight_smile:

Thanks Mora, I’ll look into that and see how I do. That sounds like it may work better… I’ve been using the ESP8266 and I can use the GET and POST with it but I haven’t been successful getting the CGI to publish. You’re idea sounds more feasible

If you want to translate the form manually to a URL, just take all the parts and put them together. The example looks like it’s missing some characters due to the formatting here, and the submit, but from the parts I can make out, it would be…

http://URL/1/pm3/cgi/admin.cgi?action=messanger&from=“admin”&by=email

Each input has a name and value, which you convert their strings to a URL encoded &name=value parameter. The URL encoding needs to convert special characters to %XX hex values.

That worked great but once posted to the CGI, another script is activated and another page runs the rest of the code… Which i can see is going to give me a headache later on… Right now I have it all working in C#.NET and it runs perfectly. I have a database which has a group of people who need to be notified if a gunshot is detected in the area. So… once the detection, a sig is sent to the arg and posts the data to the CGI. From there code on the server looks at all registries and sends out a group text message… I’m having one heck of a time trying to get the PC out of the equation. I’m now considering using a pie to accomplish what the Proton can’t…

Oh well. That was in the GET field instead of POST anyway. I think there are a lot of ways to accomplish this, but can’t think of anything without a server to at least manage an email database and send secure email. Direct (POP3/SMPT with SSL) would be a pain unless someone else already wrote it. The Pi is definitely capable of being a full server on its own. It seems like overkill though.