0

我有一个问题,我不太清楚使用哪种 .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&amp; 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?

谢谢。

4

1 回答 1

0

问题不在于编码,但在我的实际代码中,我有一个更大的字符串,我用它来设置 BankAccountDetails 并且没有意识到每当我更改它以添加特殊字符时,我都会用一个更长的字符串来设置它,这使它超过了最大值字段的长度。它现在工作正常。谢谢大家。

于 2020-11-05T07:46:50.877 回答