Как выполнить HTTPS-запись в конечную точку REST в PHP - PullRequest
0 голосов
/ 16 сентября 2011

У меня есть следующий кусок XML. Который используется для инициирования новой транзакции в платежном шлюзе POLi.

<InitiateTransactionRequest
xmlns="http://schemas.datacontract.org/2004/07/Centricom.POLi.Services.MerchantAPI.Contract
s" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<AuthenticationCode>MerchantPassword</AuthenticationCode>
<Transaction
xmlns:dco="http://schemas.datacontract.org/2004/07/Centricom.POLi.Services.MerchantAPI.DCO"
>
<dco:CurrencyAmount>15.00</dco:CurrencyAmount>
<dco:CurrencyCode>AUD</dco:CurrencyCode>
<dco:MerchantCheckoutURL>http://www.pricebusterdvd.com/checkout</dco:MerchantCheckoutURL>
<dco:MerchantCode>PriceBusterDVD</dco:MerchantCode>
<dco:MerchantData>MerchantDataAssociatedWithTransaction</dco:MerchantData>
<dco:MerchantDateTime>2008-08-18T14:01:02</dco:MerchantDateTime>
<dco:MerchantHomePageURL>http://www.pricebusterdvd.com/home</dco:MerchantHomePageURL>
<dco:MerchantRef>MerchantReferenceAssociateWithTransaction</dco:MerchantRef>
<dco:NotificationURL>http://www.pricebusterdvd.com/notification</dco:NotificationURL>
<dco:SelectedFICode i:nil="true" />
<dco:SuccessfulURL>http://www.pricebusterdvd.com/successful</dco:SuccessfulURL>
<dco:Timeout>1000</dco:Timeout>
<dco:UnsuccessfulURL>http://www.pricebusterdvd.com/unsuccessful</dco:UnsuccessfulURL>
<dco:UserIPAddress>65.2.45.1</dco:UserIPAddress>
</Transaction>
</InitiateTransactionRequest>

Это URL-адрес конечной точки REST ..

https://merchantapi.apac.paywithpoli.com/MerchantAPIService.svc/Xml/transaction/initiate

The request content-type must be set to ‘text/xml’ and the following XML data included within the request body:

Я попытался отправить его с помощью CURL, но получил ошибку ..

$url='https://merchantapi.apac.paywithpoli.com/MerchantAPIService.svc/Xml/transaction/initiate';   
    $curl = curl_init($url);
    curl_setopt($curl, CURLOPT_PORT, $server['port']);
    curl_setopt($curl, CURLOPT_HEADER, 0);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($curl, CURLOPT_FORBID_REUSE, 1);
    curl_setopt($curl, CURLOPT_FRESH_CONNECT, 1);
    curl_setopt($curl, CURLOPT_POST, 1);
    curl_setopt($curl, CURLOPT_HTTPHEADER, Array("Content-Type: text/xml"));
    curl_setopt($curl, CURLOPT_POSTFIELDS, $parameters);  
    $response = curl_exec($curl);       $response=str_replace('<a:','<',$response);$response=str_replace('</a:','</',$response);
    $result = simplexml_load_string($response);
    print_r($result);

Ошибка Объект SimpleXMLElement ([Код] => Объект SimpleXMLElement ([Значение] => Получатель [Подкод] => Объект SimpleXMLElement ([Значение] => a: InternalServiceFault)) [Причина] => Объект SimpleXMLElement ([Text] = > Серверу не удалось обработать запрос из-за внутренней ошибки. Для получения дополнительной информации об ошибке либо включите IncludeExceptionDetailInFaults (либо из ServiceBehaviorAttribute, либо из поведения конфигурации) на сервере, чтобы отправить информацию об исключении обратно клиенту или включите трассировку в соответствии с документацией Microsoft .NET Framework 3.0 SDK и проверьте журналы трассировки сервера.))

...