脚本宝典收集整理的这篇文章主要介绍了api – 使用CakePHP通过Put发送XML,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
这是我正在尝试的:
$HttpSocket = new HttpSocket(); $result = $HttpSocket->put($put,$fh);
$xMLObject = Xml::FromArray($xmlArray); $xmlString = $xmlObject->asXML(); $fh = foPEn('PHP://memory','rw'); fwrITe($fh,$xmlString); rewind($fh);
因此,您可以直接发送xml字符串,远程服务器将在Raw Post Data i中读取它.即的file_get_contents( “PHP://输入”)
这有效:
$http = new HttpSocket(); $xml_data = Xml::fromArray($data); $xml_string = $xml_data->asXML(); $response = $http->put('http://example.COM',$xml_string);
为了演示它,我在’Controllers / RequestXmltestController.PHP'(代码如下)下创建了一个名为RequestXmlTestController的Controller,并在’RequestXmlTests / index.ctp’下提交了一个空视图.
控制器代码:
<?PHP App::uses('AppController','Controller'); /** * RequestXmlTest Controller * */ class RequestXmlTestController extends AppController { /** * Use no Model */ public $uses = array(); /** * index action */ public function index(){ App::uses('HttpSocket','Network/Http'); App::uses('Xml','Utility'); $http = new HttpSocket(); $data = array( 'type' => array('name' => 'Campaign','data' => array( array('name' => 'Come eat at Joe\'s','PRoducts' => array('adserver','Analytics')) )) ); $xml_data = Xml::fromArray($data); $xml_string = $xml_data->asXML(); $response = $http->put(Router::url(array('action' => 'test'),true),$xml_string); debug($response); } /** * test action * Test the requests and dump Raw Post Data and Cake's Request object */ public function test(){ var_dump(array('raw_post_data' => file_get_contents("PHP://input"))); echo "\n\n"; VAR_dump($this->request); exit; $this->render('index'); } }
参考文献:
HttpSocket Documentation
以上是脚本宝典为你收集整理的api – 使用CakePHP通过Put发送XML全部内容,希望文章能够帮你解决api – 使用CakePHP通过Put发送XML所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。