<request> <action> getCategories </action> <params> </params> </request>

时间:2013-10-07 07:57:24

标签: php curl

我收到了这段代码,我需要编写其他代码才能使其正常工作:

<ul>
    <li><a href="?test=1">1</a></li> 
    <li><a href="?test=2">2</a></li>
</ul>
<hr>
<?php
$iTest = (int) $_GET['test'];
$sXML = '<?xml version="1.0" encoding="UTF-8"?>'."\n";
switch ($iTest) {
    case 1:
        $sXML .= '<request>
  <action>getCategories</action> 
  <params />
</request>';
        break;
    case 2:
        $sXML .= '<request>
  <action>getProducts</action>
  <params>
    <catid>1</catid>
    <page>1</page>
  </params> 
</request>';
        break;
    default:
        exit();
        break;
}

我实际上明白它应该做什么,但我需要编写一个输入文件,根据动作发送做一些事情,我该如何对待:

<request>
      <action>getProducts</action>
      <params>
        <catid>1</catid>
        <page>1</page>
      </params> 
    </request>

如果它只是一个简单的变量,一切都会好的,但现在我不知道如何绕过它

这里对我来说很清楚,只需将sXML发送到输入并返回结果:

$oCurl = curl_init();
curl_setopt($oCurl, CURLOPT_URL, 'http://localhost/joboffer/input.php');
curl_setopt($oCurl, CURLOPT_POST, true); 
curl_setopt($oCurl, CURLOPT_POSTFIELDS, $sXML);
curl_setopt($oCurl, CURLOPT_SSL_VERIFYPEER,false); 
curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($oCurl, CURLOPT_FRESH_CONNECT, true);
curl_setopt($oCurl, CURLOPT_HTTPHEADER, 
    array(
        'Content-type: text/xml; charset=UTF-8', 
        'Expect: '
    )
);

$sRespond = curl_exec($oCurl);
$iRespondCode = curl_getinfo($oCurl, CURLINFO_HTTP_CODE);
curl_close($oCurl);

echo '<pre>RESPOND  ', $iRespondCode, "\n\n", htmlentities($sRespond);

0 个答案:

没有答案