使用curl发布xml

时间:2013-09-28 08:07:45

标签: php xml curl

我试图通过HTTP POST方法发布xml ...代码工作正常并显示所需的消息..“数据已成功接收”..问题是,在后端查找时,数据不是发布在议程创意后端..我可以搞砸了吗?提前谢谢。

<?php   

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

  // Send to remote and return data to caller.
 $result = curl_exec($ch);
 curl_close($ch);
 return $result;
 }

 $postargs = '<?xml version="1.0" encoding="utf-8"?>
 <Vacancy>
 <Poster>LOGICMELON</Poster>
 <Action>Add</Action>
 <Username>agendacreative</Username>
 <Password>A12!.ndasa55</Password>
 <JobReference>AC Test 1</JobReference>
 <JobTitle>AC Test 1</JobTitle>
 <JobType>F</JobType>
 <JobHours>F</JobHours>
 <Industry>137</Industry>
 <SalaryCurrency>GBP</SalaryCurrency>
 <SalaryFrom>100.0000</SalaryFrom>
 <SalaryTo>200.0000</SalaryTo>
 <SalaryPer>D</SalaryPer>
 <SalaryBenefits>Benefits</SalaryBenefits>
 <Salary>£100 - 200 per day + Benefits</Salary>
 <JobLocation>4</JobLocation>
 <JobCountry>GB</JobCountry>
 <JobDescription>&lt;p&gt;LOGIC MELON TEST VACANCY - PLEASE DO NOT APPLY!!!&lt;/p&gt;&lt;p&gt;Testing the initial integration to Agenda Creative to make sure that the template is compiled properly andt hat the fields are getting sent through correctly.&lt;/p&gt;&lt;p&gt;THIS IS A LOGIC MELON TEST VACANCY - PLEASE DO NOT APPLY FOR THIS ROLE AS IT DOES NOT EXIST!!!&lt;/p&gt;&lt;p&gt;&amp;euro; - Testing Euro Sign&lt;/p&gt;&lt;p&gt;&amp;pound; - Testing Pound Sign&lt;/p&gt;</JobDescription>
<ContactName>Logic Melon Support</ContactName>
<ContactEmail>jade.sinclair.1267EC41.0@applythis.net</ContactEmail>
<ApplicationEmail>jade.sinclair.1267EC41.0@applythis.net</ApplicationEmail>
<ApplicationURL></ApplicationURL>
<WeeksToAdvertise>1</WeeksToAdvertise>
</Vacancy>
';
    $request = "http://agendacreativerecruitment.co.uk/feed.php";
    echo (sendXmlOverPost($request, $postargs));
?>

1 个答案:

答案 0 :(得分:0)

我不了解Agenda Creative。但尝试这样的事情?

curl_setopt($ch, CURLOPT_POSTFIELDS, array('xml' => $xml));

其中'xml'是xml数据所在的post字段。