[英]Posting xml string with curl to a webservice
梦night以求的理解为什么这是行不通的。
我需要将线索从数据库发布到线索池服务器。
这是我正在使用的代码
$xmlcontent = '<?xml version="1.0"?>
<LeadpoolImport xmlns="http://www.xxxxxx.com/ns/LeadpoolImport/Version2.0" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Applications>';
$xmldetals = '<Application>
<LeadBatch>1</LeadBatch>
<Source>1</Source>
<MainApplicant>
<Applicant>
<Type>Client</Type>
<Name>';
$xmlt = "<Title>".$_GET['tit']."</Title>";
$xmls = "<Surname>".$_GET['sname']."</Surname>";
$xmlend = '</Name>
<ContactDetails>
<ContactTelephone>
<TelephoneNumber>00000000000000</TelephoneNumber>
</ContactTelephone>
</ContactDetails>
</Applicant>
</MainApplicant>
</Application>
</Applications>
</LeadpoolImport>';
$xmltext = "xmlText=$xmlcontent$xmldetals$xmlt$xmls$xmlend&RequestID=54345456";
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_URL, "http://xxxxxxxxxx:xx/Leadpool/importleads.asmx?op=sendxxxxxLeadXML");
//curl_setopt($ch, CURLOPT_URL, "http://nxxxxxx.xx.xx/dump.php?");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER , 0);
curl_setopt($ch, CURLOPT_POSTFIELDS, "$xmltext");
$result = curl_exec ($ch);
当我在服务器上发布到转储文件时,它会创建一个格式正确的xml字符串,当直接发布到Web服务中时,它可以完美地工作。
问题是当我尝试直接向其发布时,我们什么也没猜到它与我发送帖子的方式有关的问题
任何帮助都会很棒
谢谢
您应该在POST中对发送的数据进行urlencode。
更改以下行: $xmltext="xmlText=".urlencode("$xmlcontent$xmldetals$xmlt$xmls$xmlend")."&RequestID=54345456";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.