2017-10-06 6 views
1

J'ai eu le code PHP suivant qui publie des données XML et récupère le statut comme post réussi ou non. Ce code a été envoyé par l'entreprise pour tester l'API, mais comme le développement est fait en utilisant ColdFusion j'ai écrit un code, donné ci-dessous dans ColdFusion, Il envoie une réponse OK mais retourne un code d'erreur selon le comportement ou l'API.Passage de code XML pour obtenir Repose à partir de l'API à l'aide de Coldfusion

<?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; 
?> 

et son travail de retour d'un état de réussite

Je veux avoir le code écrit dans ColdFusion et moi avons écrit le code suivant

<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#"> 

Mais ce code renvoie l'erreur Statut

J'ai essayé de résoudre le problème mais je n'arrive pas à le résoudre. Quelqu'un peut-il aider, où je me suis trompé.

Merci

Répondre