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#">
但這代碼返回錯誤狀態
我一直在試圖解決這個問題,但無法解決。有人能幫助我,哪裏出錯了。
謝謝