我有一个问题,我不太清楚使用哪种 .net 编码方法来设置上述字段。这是我的代码:
Contact Contact = null;
Contacts Contacts = null;
List<Contact> ContactsList = null;
ContactsList = new List<Contact>();
Contacts = new Contacts();
//no error
Contact.BankAccountDetails = "detew";
//400 Bad Request error
Contact.BankAccountDetails = "&ew";
//I have tried encoding using:
System.Uri.EscapeDataString
System.Security.SecurityElement.Escape
System.Net.WebUtility.HtmlEncode
System.Xml.XmlConvert.EncodeName
System.Web.HttpUtility.HtmlEncode
System.Web.HttpUtility.UrlEncode
System.Web.HttpUtility.HtmlAttributeEncode
//But nothing works.
//This is the passed xml with error:
Xero.NetStandard.OAuth2.Client.ApiException: 'Xero API 400 error calling UpdateContact :{
"ErrorNumber": 10,
"Type": "ValidationException",
"Message": "A validation exception occurred",
"Elements": [
{
"ContactID": "89d59636-6524-47b2-b047-0000000000000",
"ContactNumber": "Cust_4",
"AccountNumber": "Cust_4",
"ContactStatus": "ACTIVE",
"Name": "cpName",
"FirstName": "MyCustomerFirstName2",
"LastName": "MyCustomerLastName1",
"EmailAddress": "sfgdg@sdfs.lo",
"SkypeUserName": "",
"BankAccountDetails": "bkname& bankacname sortcode accnumber bicswift iban",
"UpdatedDateUTC": "\/Date(1604408524790)\/",
"ContactGroups": [],
"IsSupplier": false,
"IsCustomer": false,
"ContactPersons": [],
"HasAttachments": false,
"HasValidationErrors": true,
"ValidationErrors": [
{
"Message": "The BankAccountDetails field cannot be more than 50 characters long."
}
]
}
]
}'
根据线程https://community.xero.com/developer/discussion/32311#answer32331转换为 UTF8(如何在 C# 中将字符串转换为 UTF-8? )也不起作用。
也许我需要将 Content-Type 设置为 xml,但不确定它是如何使用 Xero DSK 完成的。也许在建立连接时通过 XeroConfiguration?
谢谢。