2008-10-26 10 views
7

मैंने PHP4/curl के माध्यम से https पर xml भेजने के लिए एक वर्ग/फ़ंक्शन लिखा, बस यह सोचकर कि यह सही दृष्टिकोण है या यदि कोई बेहतर है।PHP4: curl के माध्यम से HTTPS/POST पर XML भेजें?

ध्यान दें कि PHP5 वर्तमान में कोई विकल्प नहीं है।

/** 
* Send XML via http(s) post 
* 
* curl --header "Content-Type: text/xml" --data "<?xml version="1.0"?>...." http://www.foo.com/ 
* 
*/ 
function sendXmlOverPost($url, $xml) { 
    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_URL, $url); 

    // For xml, change the content-type. 
    curl_setopt ($ch, CURLOPT_HTTPHEADER, Array("Content-Type: text/xml")); 

    curl_setopt($ch, CURLOPT_POST, 1); 
    curl_setopt($ch, CURLOPT_POSTFIELDS, $xml); 

    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // ask for results to be returned 
    if(CurlHelper::checkHttpsURL($url)) { 
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); 
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); 
    } 

    // Send to remote and return data to caller. 
    $result = curl_exec($ch); 
    curl_close($ch); 
    return $result; 
} 

चीयर्स!

+0

वाह, नहीं वर्तमान में एक विकल्प पर? :(इसके अलावा, अगर आप curl पर सेट नहीं हैं, तो HTTP_Request (http://pear.php.net/package/HTTP_Request) देखें। – Till

उत्तर

-1

सबसे पीएचपी प्रतिष्ठानों

के साथ प्रदान की SoapClient वर्ग का प्रयोग करें

एक उदाहरण है:

$soap = new SoapClient("http://some.url/service/some.wsdl"); 
$args = array("someTypeName" => "someTypeValue" 
       "someOtherTypeName" => "someOtherTypeValue"); 

$response = $soap->executeSomeService($args); 

print_r($response); 
+0

चीयर्स, लेकिन मुझे नहीं लगता कि एक्सएमएल एपीआई मैं वास्तव में उपयोग कर रहा हूं SOAP , सिर्फ एक पोस्ट से एक स्ट्रिंग पढ़ता है। – starmonkey

4

प्रोटोकॉल का उपयोग कर रहे XML-RPC है (लगता है कि आप क्या कहा के आधार पर यह) और आप कम से कम PHP 4.2 का उपयोग कर रहे हैं, पुस्तकालयों और संसाधनों के लिए http://phpxmlrpc.sourceforge.net/ पर एक नज़र डालें।

3

$ ch = curl_init ($ serviceUrl);

if($this -> usingHTTPS()) 
    { 
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); 
      curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, $this->sslVerifyHost); 

    } 

    curl_setopt($ch,CURLOPT_POST,TRUE); 
    curl_setopt($ch, CURLOPT_HEADER, FALSE);  
    curl_setopt ($ch, CURLOPT_POSTFIELDS, "OTA_request=".urlencode($this->xmlMessage)); 

    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); 

    $this->xmlResponse = curl_exec ($ch); 

    $this -> callerFactory -> dbgMsg('xmlResponse: <hr><pre>'.htmlentities($this->xmlResponse).'</pre><hr>'. curl_error($ch)); 
    curl_close ($ch); 

    $this->checkResponse(); 
4

ग्रेट सॉल्यूशन! यहां भी इसी तरह की एक मिल गया:

इसके अलावा वे से पता चला है कि कैसे एक्सएमएल के इस प्रकार प्राप्त करने के लिए/JSON सर्वर

// here you can have all the required business checks 
if ($_SERVER['REQUEST_METHOD'] === 'POST'){ 
    $postText = file_get_contents('php://input'); 
}