为了账号安全,请及时绑定邮箱和手机立即绑定

使用php以编程方式传递soap值

使用php以编程方式传递soap值

PHP
陪伴而非守候 2021-04-30 14:16:20
我有以下php脚本来更新xml值://The XML string that you want to send.$xml = '<?xml version="1.0" encoding="ISO-8859-1"?><reminder>    <date>2019-20-02T10:45:00</date>    <heading>Meeting</heading>    <body>Team meeting in Boardroom 2A.</body></reminder>';//The URL that you want to send your XML to.$url = 'http://localhost/xml';//Initiate cURL$curl = curl_init($url);//Set the Content-Type to text/xml.curl_setopt ($curl, CURLOPT_HTTPHEADER, array("Content-Type: text/xml"));//Set CURLOPT_POST to true to send a POST request.curl_setopt($curl, CURLOPT_POST, true);//Attach the XML string to the body of our request.curl_setopt($curl, CURLOPT_POSTFIELDS, $xml);//Tell cURL that we want the response to be returned as//a string instead of being dumped to the output.curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);//Execute the POST request and send our XML.$result = curl_exec($curl);//Do some basic error checking.if(curl_errno($curl)){    throw new Exception(curl_error($curl));}//Close the cURL handle.curl_close($curl);//Print out the response output.echo $result;但是,我打算做的是,我想使用动态值制作$ xml,已经尝试过这样的事情:$date= $_POST['datevalue'];$heading= $_POST['meetingvalue'];$body= $_POST['bodycontent'];$xml = '<?xml version="1.0" encoding="ISO-8859-1"?><reminder>    <date>{$date}</date>    <heading>{$date}</heading>    <body>{$date}</body></reminder>';不幸的是,上面的代码无法正常工作,似乎{$ date}并没有发送任何东西来休息SOAP。任何人都有解决此问题的经验,
查看完整描述

2 回答

?
红糖糍粑

TA贡献1815条经验 获得超6个赞

我不是这方面的专家,所以请给个建议,尝试使用双引号,如下所示:


$xml = "<?xml version='1.0' encoding='ISO-8859-1'?>

<reminder>

  <date>{$date}</date>

  <heading>{$date}</heading>

  <body>{$date}</body>

</reminder>";

希望能有所帮助


查看完整回答
反对 回复 2021-05-14
?
守着星空守着你

TA贡献1799条经验 获得超8个赞

替换字符串呢?


$xml = '<?xml version="1.0" encoding="ISO-8859-1"?>

    <reminder>

        <date>%s</date>

        <heading>%s</heading>

        <body>%s</body>

    </reminder>';


$message = sprintf($xml, $date, $heading, $body);

无论如何,完整的动态XML方法可以使用DomDocument类。


$doc = new DomDocument('1.0', 'iso-8859-1');

$reminder = $doc->createElement('reminder');


$date = $doc->createElement('date', $dateValue);

$reminder->appendChild($date);


$heading = $doc->createElement('heading', $headingValue);

$reminder->appendChild($heading);


$body = $doc->createElement('body', $bodyValue);

$reminder->appendChild($body);


$doc->appendChild($reminder);

$xmlString = $doc->saveXML();

该$xmlString变量将您的xml树包含为带有动态值的字符串。


查看完整回答
反对 回复 2021-05-14
  • 2 回答
  • 0 关注
  • 144 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信