2017-10-06 28 views
1

我有以下PHP代码,用于发布XML数据并检索状态为成功发布与否。该代码由公司发送来测试api,但由于开发是使用ColdFusion完成的,因此我编写了一个代码,在ColdFusion中给出以下代码,它发送OK响应,但根据行为或API返回错误代码。传递XML代码以使用Coldfusion从API中获得休息

<?php 
define('blueEx', "http://benefit.blue-ex.com/api/post.php"); 
$xml = '<?xml version="1.0" encoding="utf-8"?> 
<BenefitDocument> 
<AccessRequest> 
<DocumentType>1</DocumentType> 
<TestTransaction>Y</TestTransaction>*For Testing purpose, after testing leave it blank 
<ShipmentDetail> 
      <ShipperName></ShipperName> 
      <ShipperAddress></ShipperAddress> 
      <ShipperContact></ShipperContact> 
      <ShipperEmail></ShipperEmail> 
      <ConsigneeName>Tayyab</ConsigneeName> 
      <ConsigneeAddress>202-N,DHA,Lahore</ConsigneeAddress> 
      <ConsigneeContact>03004306499</ConsigneeContact> 
      <ConsigneeEmail>[email protected]</ConsigneeEmail> 
      <CollectionRequired>Y</CollectionRequired> 
      <ProductDetail>Some Product</ProductDetail> 
      <ProductValue>200</ProductValue> 
      <OriginCity>ISB</OriginCity> 
      <DestinationCountry>PK</DestinationCountry> 
      <DestinationCity>LHE</DestinationCity> 
      <ServiceCode>BG</ServiceCode> 
      <ParcelType>P</ParcelType> 
      <Peices>1</Peices> 
      <Weight>1</Weight> 
      <Fragile>N</Fragile> 
      <ShipperReference>9010191</ShipperReference> 
      <InsuranceRequire>N</InsuranceRequire> 
      <InsuranceValue></InsuranceValue> 
      <ShipperComment>xxxx</ShipperComment> 
</ShipmentDetail> 
</AccessRequest> 
</BenefitDocument>'; 
$c = curl_init();  
    curl_setopt($c, CURLOPT_URL, blueEx); 
    curl_setopt($c, CURLOPT_RETURNTRANSFER, 1); 
    curl_setopt($c, CURLOPT_USERPWD, "sphere.technologies:sphere.tech"); 
    curl_setopt($c, CURLOPT_POST, 1); 
    curl_setopt($c, CURLOPT_POSTFIELDS, array('xml'=>$xml)); 
    curl_setopt($c, CURLOPT_HTTPHEADER, array('Content-Type=application/soap+xml', 'charset=utf-8')); 
    $result = curl_exec ($c); 
    $xres = simplexml_load_string($result); 
    $st = $xres->status; 
    $no = $xres->message; 

    echo $st . ' - ' . $no; 
?> 

及其工作返回成功状态

我想要写的ColdFusion的代码,我写了下面的代码

<cfset objCFHttpProperties = { 
    Useragent = "#CGI.http_user_agent#", 
    Username = "sphere.technologies", 
    Password = "sphere.tech" 
    } /> 
<cfxml variable="xmlString"> 
    <BenefitDocument> 
     <AccessRequest> 
      <DocumentType>1</DocumentType> 
      <TestTransaction>Y</TestTransaction> 
     <ShipmentDetail> 
      <ShipperName></ShipperName> 
      <ShipperAddress></ShipperAddress> 
      <ShipperContact></ShipperContact> 
      <ShipperEmail></ShipperEmail> 
      <ConsigneeName>Tayyab</ConsigneeName> 
      <ConsigneeAddress>202-N,DHA,Lahore</ConsigneeAddress> 
      <ConsigneeContact>03004306499</ConsigneeContact> 
      <ConsigneeEmail>[email protected]</ConsigneeEmail> 
      <CollectionRequired>Y</CollectionRequired> 
      <ProductDetail>Some Product</ProductDetail> 
      <ProductValue>200</ProductValue> 
      <OriginCity>ISB</OriginCity> 
      <DestinationCountry>PK</DestinationCountry> 
      <DestinationCity>LHE</DestinationCity> 
      <ServiceCode>BG</ServiceCode> 
      <ParcelType>P</ParcelType> 
      <Peices>1</Peices> 
      <Weight>1</Weight> 
      <Fragile>N</Fragile> 
      <ShipperReference>9010191</ShipperReference> 
      <InsuranceRequire>N</InsuranceRequire> 
      <InsuranceValue></InsuranceValue> 
      <ShipperComment></ShipperComment> 
     </ShipmentDetail> 
    </AccessRequest> 
</BenefitDocument> 
</cfxml> 
<cfhttp url="http://benefitx.blue-ex.com/api/post.php" method="post" result="result" attributecollection="#objCFHttpProperties#"> 
    <cfhttpparam type="header" name="Content-Type" value="application/soap+xml"/> 
    <cfhttpparam type="xml" name="xmlString" value="#xmlString#" /> 
</cfhttp> 
<cfdump var="#result#"> 

但这代码返回错误状态

我一直在试图解决这个问题,但无法解决。有人能帮助我,哪里出错了。

谢谢

回答