当前位置:  开发笔记 > 编程语言 > 正文

PHP4:通过cURL通过HTTPS/POST发送XML?

如何解决《PHP4:通过cURL通过HTTPS/POST发送XML?》经验,为你挑选了0个好方法。

我编写了一个类/函数,通过PHP4/cURL通过https发送xml,只是想知道这是否是正确的方法,或者是否有更好的方法.

请注意,PHP5目前不是一个选项.

/**
 * Send XML via http(s) post
 *
 * curl --header "Content-Type: text/xml" --data "...." 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;
}

干杯!

推荐阅读
勤奋的瞌睡猪_715
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有