XML request is not well-formed or request is incomplete

对着背影说爱祢 提交于 2021-02-07 07:55:59

问题


We are using virtual merchant payment gateway in our application:

https://www.myvirtualmerchant.com/VirtualMerchant/download/developerGuide.pdf

I am trying to record a CCSALE transaction but I keep getting this error:

<?xml version="1.0" encoding="UTF-8"?>
<txn><errorCode>6042</errorCode><errorName>Invalid Request Format</errorName><errorMessage>XML request is not well-formed or request is incomplete.</errorMessage></txn>

The XML I am passing in request in Fiddler POST is:

<txn>
<ssl_merchant_id>my_mer_id</ssl_merchant_id>
<ssl_user_id>my_usr_id</ssl_user_id>
<ssl_pin>my_pin</ssl_pin>
<ssl_test_mode>false</ssl_test_mode>
<ssl_transaction_type>ccsale</ssl_transaction_type>
<ssl_card_number>4111111111111111</ssl_card_number>
<ssl_exp_date>1215</ssl_exp_date>
<ssl_amount>1.00</ssl_amount>
</txn>

I have simply removed my merchant id, user id and ssl pin. The rest of the information is just as it is. I am posting the data to: https://demo.myvirtualmerchant.com/VirtualMerchantDemo/processxml.do

Can anybody let me know why does it say XML is not well formed?


回答1:


First of all, after hours of frustration I find PHP way of doing this very retarded. Since this XML error was so persistent, I wanted to try this in Coldfusion and in 2-3 minutes, the whole thing was done, no XML errors, no SSL crap returned from the API. Anyway, enough with the venting! This is probably what you need to prevent that XML well formedness super duper message :

curl_setopt($ch, CURLOPT_POSTFIELDS, array("xmldata=" . $fields_string));

Assuming you are following their documentation and you are holding the variables in fields_string all you need to do is type something that mimics a variable for the API. In this case, xmldata will do.

I have yet to listen to the answer which throws this : Curl error: SSL read: error:00000000:lib(0):func(0):reason(0), errno 104

This is thanks to listening to the errors, otherwise $result returned empty after I got rid of XML error. So, here it goes :

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, array("xmldata=" . $fields_string));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
$result = curl_exec($ch);

if(curl_errno($ch))
    echo 'Curl error: ' . curl_error($ch);
else
    echo 'the return is ' . $result;

SSL is not setup yet so why the heck they bothered with CURLOPT_SSL_VERIFYPEER and CURLOPT_SSL_VERIFYHOST? It's not working even when it's false, this whole thing turned out Charlie Foxtrot!




回答2:


I was getting this error as well, here is my working curl function

    public function send_curl_xml($xml=NULL){

    $data = http_build_query(array("xmldata"=>$xml));

    $headers = array(
        "Accept: application/xml",
        "Content-type: application/x-www-form-urlencoded"
        //,"Content-length: " . strlen($data)
    );

    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);

    $response = curl_exec($ch);

    //echo $response;

    if(curl_errno($ch)){
        print curl_error($ch);
        return false;
    } else {
        curl_close($ch);
        return $data;
    }
}

$xml variable is DOCDocument object, be sure to use $xml->saveHTML() if you are dynamically generating your xml (The key here is to remove "" line in your xml string.)



来源:https://stackoverflow.com/questions/12158960/xml-request-is-not-well-formed-or-request-is-incomplete

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!