Jose_49, on 02 February 2013 - 17:42, said:
I did this by doing the following.
<snip>
You've misunderstood, one of the two pages the OP wants to send the data to is on another web service!
Axel, on 02 February 2013 - 17:43, said:
One way you could perhaps find out: grab the POSTman addon for Google Chrome and use it to send a request. Set the method to POST, place your json encoded string in the body (RAW mode), and set the 'Content-Type' header to 'application/json', then see what you get back.
Axel, on 02 February 2013 - 17:43, said:
I can quite easily get a webpage into a variable using php:
$url = "https://www.formstack.com/forms/index.php"
function get_data($url) {
$ch = curl_init();
$timeout = 5;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
Now is it possible to somehow forward the $_POST data in the curl request so that I get the relevant data?
This is the method I would suggest you use to do it, submitting to your own PHP script, then with that submitting to the other web service.
Assuming the web service accepts JSON encoded data, you could use the following code:
$data = json_encode($_POST);
$ch = curl_init('https://www.formstack.com/forms/index.php');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json'
);
$result = curl_exec($ch);
If the web service does not accept JSON:
The default encoding for form data in a POST request is application/x-www-form-urlencoded. I just made a little test script, and it does not seem that PHP keeps a copy of it in this format in a server variable. The application/x-www-form-urlencoded format is described here:
http://www.w3.org/TR...tml#h-17.13.4.1. It's essentially the same as query string format. e.g. forename=foo&surname=bar, and certain characters being encoded.
Thankfully though, there is no need to translate the $_POST array into an application/x-www-form-urlencoded string, you can simply give CURLOPT_POSTFIELDS an array, and it'll sort it out for you!
$ch = curl_init('https://www.formstack.com/forms/index.php');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $_POST);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
Axel, on 02 February 2013 - 18:20, said:
Obviously this is command line usage (I'm sure you knew that, just making sure). Note that the data is in application/x-www-form-urlencoded form, as mentioned above! You could probably pass this as a string to php's exec() function, but that
could very likely be extremely insecure, so I would strongly discourage it!