我正在尝试在Actionscript 3中为Authorize.net创建一个REST API。我正在测试将数据发送到REST API的函数。
这是我的函数,它创建一个XML文件并将其发送给Authorize.net以创建客户档案。
public function createProfile(card:Card, customerType:String, description:String=null, merchantCustomerId:String=null, email:String=null):void
{
//Append tag.
var sendingObj:XML = <createCustomerProfileRequest xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd" />
sendingObj.merchantAuthentication.name = log;
sendingObj.merchantAuthentication.transactionKey = tK;
if (merchantCustomerId == null && description == null && email == null)
{
throw new Error("At least one profile element (description, merchantCustomerID, email) must be present");
return;
}
if (merchantCustomerId != null)
sendingObj.profile.merchantCustomerId = merchantCustomerId;
if (description != null)
sendingObj.profile.description = description;
if (email != null)
sendingObj.profile.email = email;
sendingObj.profile.paymentProfiles.customerType = customerType;
sendingObj.profile.paymentProfiles.payment.creditCard.cardNumber = card.number;
sendingObj.profile.paymentProfiles.payment.creditCard.expirationDate = card.expiration;
sendingObj.validationMode = "none";
var rq:URLRequest = new URLRequest(endpoint);
rq.method = URLRequestMethod.POST;
rq.requestHeaders.push(new URLRequestHeader("Content-Type", "text/xml"));
var urll:URLLoader = new URLLoader();
urll.data = '<?xml version="1.0" encoding="utf-8"?>\n' + sendingObj.toXMLString();
urll.dataFormat = URLLoaderDataFormat.TEXT;
trace("URLData:");
trace(urll.data);
urll.addEventListener(IOErrorEvent.IO_ERROR, handleIOError);
urll.addEventListener(Event.COMPLETE, handleCardChargeComplete);
urll.load(rq);
}
跟踪的XML是正确的,并且在their web page上粘贴到其脚本测试器中时,与生成完全一样。
<?xml version="1.0" encoding="utf-8"?>
<createCustomerProfileRequest xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd">
<merchantAuthentication>
<name>===My Login===</name>
<transactionKey>===My Key===</transactionKey>
</merchantAuthentication>
<profile>
<description>autogen</description>
<paymentProfiles>
<customerType>individual</customerType>
<payment>
<creditCard>
<cardNumber>4111111111111111</cardNumber>
<expirationDate>12/20</expirationDate>
</creditCard>
</payment>
</paymentProfiles>
</profile>
<validationMode>none</validationMode>
</createCustomerProfileRequest>
然而我的回复是一个json文件,声明缺少根元素。问题是什么?我看到quite a few others出现了这个问题,但他们通过他们的重复语言问题全部解决了。
{"messages":{"resultCode":"Error","message":[{"code":"E00003","text":"Root element is missing."}]}}