Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Token generation
- $timestamp = time();
- $uri = "https://api.website.com/post.json";
- $password = "somePassword";
- $security_token = sha1($timestamp.$uri.$password);
- // Webservice call
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $uri);
- curl_setopt($ch, CURLOPT_HEADER, false);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- $post = array();
- $post["timestamp"] = $timestamp;
- $post["security_token"] = $security_token;
- curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post));
- curl_setopt($ch, CURLOPT_POST, true);
- // USE THIS CODE TO CHECK THAT SSL CERTIFICATE IS VALID:
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
- curl_setopt($ch, CURLOPT_CAINFO, "path/to/certifcate/file/certificate.crt");
- $ret = curl_exec($ch);
- // Check response
- if(curl_errno($ch)) {
- curl_close($ch);
- die("CURL error: ".curl_error($ch));
- }
- $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
- if($http_code != 200) {
- die("Server error, HTTP code: $http_code");
- }
- curl_close($ch);
- // Parse response
- try {
- $json = json_decode($ret);
- var_dump($json);
- }
- catch(Exception $e) {
- die("Failed to decode server response");
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement