Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* .. */
- /* curl_init() part of send_request() */
- $curl = curl_init($url);
- curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($curl, CURLOPT_FAILONERROR, false);
- curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
- curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
- curl_setopt($curl, CURLOPT_POST, 1);
- curl_setopt($curl, CURLOPT_POSTFIELDS, $postData);
- //* Debugging
- curl_setopt($curl, CURLOPT_VERBOSE, true);
- //*/
- $response = curl_exec($curl);
- $responseCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
- $responseContenType = curl_getinfo($curl, CURLINFO_CONTENT_TYPE);
- //* Debugging
- echo '=================== CURLINFO =====================' .PHP_EOL;
- echo $http_method . ' ' . $url .PHP_EOL;
- echo var_export(curl_getinfo($curl), true) .PHP_EOL;
- echo '=================== POST DATA ====================' .PHP_EOL;
- if(stristr($postData, 'xml')) {
- echo myPrintTool::formatXml($postData) .PHP_EOL;
- }elseif(json_decode($response)) {
- echo var_export(json_decode($postData), true) .PHP_EOL;
- } else {
- echo $postData .PHP_EOL;
- }
- echo '=================== RESPONSE =====================' .PHP_EOL;
- if(stristr($responseContenType, 'xml')) {
- echo myPrintTool::formatXml($response) .PHP_EOL;
- }elseif(stristr($responseContenType, 'json')) {
- echo var_export(json_decode($response), true) .PHP_EOL;
- } else {
- echo $response .PHP_EOL;
- }
- if (!$response) {
- echo '=================== ERROR ========================' .PHP_EOL;
- echo curl_error($curl);
- }
- /* This is just a helper class for formatting the xml */
- class myPrintTool {
- static function formatXml($xml, $htmlOutput = false, $tidy_options = array()) {
- $default_tidy_options = array(
- 'input-xml' => true,
- 'output-xml' => true,
- 'indent' => true,
- 'wrap' => false,
- );
- $tidy_options = array_merge($default_tidy_options, $tidy_options);
- $tidy = new tidy();
- $tidy->parseString($xml, $tidy_options);
- $tidy->cleanRepair();
- if($htmlOutput) {
- $tidy = '<pre>'.htmlentities($tidy).'</pre>';
- }
- return $tidy;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment