【问题标题】:Getting bad request error with Xero with SDK and OAuth v2使用 SDK 和 OAuth v2 的 Xero 出现错误的请求错误
【发布时间】:2020-11-03 16:45:36
【问题描述】:

我有一个问题,我不太清楚使用哪种 .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 (How can I transform string to UTF-8 in C#?) 也不起作用。

也许我需要将 Content-Type 设置为 xml,但我不确定它是如何使用 Xero DSK 完成的。也许在建立连接时通过 XeroConfiguration?

谢谢。

【问题讨论】:

标签: c# oauth xero


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2023-03-20
    • 2022-06-17
    • 1970-01-01
    • 1970-01-01
    • 2018-10-28
    • 2019-03-23
    • 2023-03-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多