donglian8407 2012-02-28 13:28
浏览 58

将带有curl的xml字符串发布到Web服务

Am having a nightmare understanding why this is not working.

I need to post leads from are database to are lead pool server.

here is the code am using

    $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);

When I post to a dump file on are server it creates a correctly formatted xml string which when posted directly in to the web services works perfectly.

The problem is when i try posting directly to it we get nothing am guessing its a problem with how i am sending the post

Any help would be great

thanks

  • 写回答

1条回答 默认 最新

  • dongpankao6133 2012-02-28 13:43
    关注

    You should urlencode data sending in POST.

    Change following line: $xmltext="xmlText=".urlencode("$xmlcontent$xmldetals$xmlt$xmls$xmlend")."&RequestID=54345456";

    评论

报告相同问题?

悬赏问题

  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示