7

PHP4/cURL経由でhttps経由で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;
}

乾杯!

4

4 に答える 4

4

素晴らしい解決策!ここでも同様のものが見つかりました:

また、サーバーでこの種のXML/JSONを受信する方法も示しています

// here you can have all the required business checks
if ( $_SERVER['REQUEST_METHOD'] === 'POST' ){
    $postText = file_get_contents('php://input');
}
于 2011-11-29T17:13:30.687 に答える
4

使用しているプロトコルが XML-RPC (あなたの発言に基づいているように見えます) で、少なくとも PHP 4.2 を使用している場合は、ライブラリとリソースについてhttp://phpxmlrpc.sourceforge.net/を参照してください。

于 2008-10-27T14:34:14.350 に答える
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();
于 2009-12-29T10:31:59.450 に答える
-1

ほとんどの PHP インストールで提供されるSoapClientクラスを使用する

例は次のとおりです。

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

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

print_r($response);
于 2008-10-26T23:27:36.567 に答える