cURL / Mailing Lists / curl-and-php / Single Mail

curl-and-php

Re: Curl SSL problem

From: Michael Horowitz <michael_at_yourcomputerconsultant.com>
Date: Mon, 17 Mar 2008 18:00:56 -0400

I just want to add I have fixed the problem

define('XML_PAYLOAD', '$result');

  is now

define('XML_PAYLOAD', $result);

$url and the user id and password are hard coded in my script I have
just substituted values here to not put them on the public net

Michael Horowitz
Your Computer Consultant
http://yourcomputerconsultant.com
561-394-9079

Michael Horowitz wrote:
> Thanks for the help so far. I resolved the ssl issue by just deciding
> to have my code ignore the ssl cert on the recepient server.
>
> From the perspective of CURL assuming I have properly created my xml
> variable does this code look like it would properly post a xml file or
> is there something else I need to add (I'm thinking to the headers)
>
>
> <?php
> /** * Define POST URL and also payload */
>
> require 'createquidataxml.php';
> $headers = get_curl_headers();
> define('XML_PAYLOAD', '$result');
> define('XML_POST_URL','$url');
> /** * Initialize handle and set options */
> $ch = curl_init();
> curl_setopt($ch, CURLOPT_URL, XML_POST_URL);
> curl_setopt($ch, CURLOPT_USERPWD, 'userid:password');
> curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
> curl_setopt($ch, CURLOPT_TIMEOUT, 4);
> curl_setopt($ch, CURLOPT_POSTFIELDS, XML_PAYLOAD);
> curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); //Don't verify ssl
> certificate
> curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
> //curl_setopt($ch, CURLOPT_HTTPHEADER, array('Connection: close'));
> /** * Execute the request and also time the transaction */
> $start = array_sum(explode(' ', microtime()));
> $result = curl_exec($ch);
> $stop = array_sum(explode(' ', microtime()));
> $totalTime = $stop - $start;
> /** * Check for errors */
> if ( curl_errno($ch) ){
> $result = 'cURL ERROR -> ' . curl_errno($ch) . ': ' .
> curl_error($ch);
> }
> else {
> $returnCode = (int)curl_getinfo($ch, CURLINFO_HTTP_CODE);
> switch($returnCode)
> {
> case 200:
> break;
> default:
> $result = 'HTTP ERROR -> ' . $returnCode;
> break;
> }
> }
>
> /** * Close the handle */
> curl_close($ch);
> /** * Output the results and time */
> echo 'Total time for request: ' . $totalTime . "\n";
> echo $result;
> /** * Exit the script */
> exit(0);
>
> function get_curl_headers() {
> $headers = array();
>
> $headers[] = "Content-Type: text/xml"; //or maybe text/xml
> $headers[] = "X-VPS-Timeout: 30";
> $headers[] = "X-VPS-VIT-OS-Name: Windows 2003 Server"; // Name of
> your OS
> $headers[] = "X-VPS-VIT-OS-Version: RHEL 4"; // OS Version
> $headers[] = "X-VPS-VIT-Client-Type: PHP/cURL"; // What you are using
> $headers[] = "X-VPS-VIT-Client-Version: 0.01"; // For your info
> $headers[] = "X-VPS-VIT-Client-Architecture: x86"; // For your info
> $headers[] = "X-VPS-VIT-Integration-Product: MyApplication"; //
> For your info, would populate with application name
> $headers[] = "X-VPS-VIT-Integration-Version: 0.01"; // Application
> version
>
> return $headers;
> }
> ?>
>
> Michael Horowitz
> Your Computer Consultant
> http://yourcomputerconsultant.com
> 561-394-9079
>
>
>
> _______________________________________________
> http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php
>
>
_______________________________________________
http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php
Received on 2008-03-17