commit 3da4a65a903ce07c13deac070355594acc148b02
parent 3ef039138165bbd8695299429cb45f94a361e8f7
Author: Marcello Stanisci <marcello.stanisci@inria.fr>
Date: Tue, 15 Nov 2016 12:48:23 +0100
Getting rid of pecl_http
Diffstat:
1 file changed, 20 insertions(+), 13 deletions(-)
diff --git a/php/helpers.php b/php/helpers.php
@@ -35,19 +35,26 @@
}
/**
- * Feed `$json` to the backend and return the "(pecl) http response object"
- * corresponding to the `$backend_relative_url` call
+ * 'body' is an array, representing the JSON to POST. NOTE: we do NOT
+ * rely on a more structured way of doing HTTP, like the one offered by
+ * pecl_http, as its installation was NOT always straightforward.
*/
- function post_to_backend($backend_relative_url, $json){
- $url = url_join("https://backend.demo.taler.net/", $backend_relative_url);
- $req = new http\Client\Request("POST",
- $url,
- array ("Content-Type" => "application/json"));
- $req->getBody()->append($json);
- // Execute the HTTP request
- $client = new http\Client;
- $client->enqueue($req)->send();
- return $client->getResponse();
+ function post_to_backend($backend_uri, $body){
+ $json = json_encode($body);
+ $c = curl_init(url_join ("https://backend.demo.taler.net/", $backend_uri));
+ $options = array(CURLOPT_RETURNTRANSFER => true,
+ CURLOPT_CUSTOMREQUEST => "POST",
+ CURLOPT_POSTFIELDS => $json,
+ // Disabling SSL for the sole purpose of speed
+ // up the tutorial, as the normal user is likely
+ // to NOT have certs for taler.net
+ CURLOPT_SSL_VERIFYHOST => false,
+ CURLOPT_SSL_VERIFYPEER => false,
+ CURLOPT_HTTPHEADER =>
+ array('Content-Type: application/json'));
+ curl_setopt_array($c, $options);
+ $r = curl_exec($c);
+ return array("status_code" => curl_getinfo($c, CURLINFO_HTTP_CODE),
+ "body" => $r);
}
-
?>