Skip to content

Instantly share code, notes, and snippets.

@ederrafo
Last active December 12, 2016 16:57
Show Gist options
  • Save ederrafo/e83c461d7f230714b5b5 to your computer and use it in GitHub Desktop.
Save ederrafo/e83c461d7f230714b5b5 to your computer and use it in GitHub Desktop.
<?php
/***********************************
* sample 1
**********************************/
$urlScriping = 'http://my-web-service-http.php';
$scriping = curl_init();
curl_setopt($scriping, CURLOPT_URL, $urlScriping);
curl_setopt($scriping, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($scriping, CURLOPT_TIMEOUT, '100');
$response = trim(curl_exec($scriping));
$response = mb_convert_encoding ($response, 'UTF-8', 'Windows-1252');
curl_close($scriping);
// echo "FILE: ",__FILE__,"<br>LINE: ", __LINE__,"<pre>"; print_r($response); echo "</pre>";
echo htmlspecialchars($response, ENT_QUOTES). '</pre>';
/***********************************
* sample 2
**********************************/
$url = "http://svecliente.enterprise.net:8080/XxxxService.svc/AnyMethod";
$parameters["usuario"] = "foo@gmail.com";
$parameters["applicationId"] = "001";
$parameters["IpCliente"] = "191.98.138.162";
$parameters["urlRedireccion"] = "AnyMethod";
$data = json_encode($parameters);
echo "<pre>",__FILE__." on line ".__LINE__,": "; print_r($data); echo "</pre>";
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
// curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data)
)
);
$result = curl_exec($curl);
$response = json_decode($result, TRUE);
curl_close($curl);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment