簡體   English   中英

將帶有curl的xml字符串發布到Web服務

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM