【发布时间】: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& 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?
谢谢。
【问题讨论】:
-
您可能正在使用 TLS 1.0/1.1,您需要使用 TLS 1.2。请参阅:developer.xero.com/documentation/oauth2/overview
-
我使用的是 TLS 1.2
-
请参阅以下内容:example-code.com/csharp/xero_oauth2.asp。下面使用 xero 中的 httpclient 并在客户端添加一个 header 用户代理。 Content-Type 也是一个以类似方式添加的标头:github.com/XeroAPI/Xero-Net/blob/…
-
谢谢,但我认为这不是使用 sdk
-
这有关系吗?您仍在使用同一个客户端并希望添加 HTTP 标头。