Я получаю сообщение об ошибке при попытке отправить сообщение.
string productJson = await Task.Run(() => JsonConvert.SerializeObject(product, Formatting.Indented));
HttpContent content = new StringContent(productJson, Encoding.UTF8, "application/json");
Uri uri = new Uri(string.Format(@"{0}/api/product/addProduct?token={1}", Configuration.ServerURL, _token.TokenValue));
var response = await _client.PostAsync(uri, content);
Модель продукта:
[XmlRoot(ElementName = "Product")]
public class Product
{
[JsonProperty(PropertyName = "name")]
[XmlElement(ElementName = "Name")]
public string Name { get; set; }
[JsonProperty(PropertyName = "code")]
[XmlElement(ElementName = "Code")]
public string Code { get; set; }
[JsonProperty(PropertyName = "ean")]
[XmlElement(ElementName = "Ean")]
public string Ean { get; set; }
[JsonProperty(PropertyName = "description")]
[XmlElement(ElementName = "Description")]
public string Description { get; set; }
[JsonProperty(PropertyName = "value1")]
[XmlElement(ElementName = "Value1")]
public string Value1 { get; set; }
[JsonProperty(PropertyName = "value2")]
[XmlElement(ElementName = "Value2")]
public string Value2 { get; set; }
[JsonProperty(PropertyName = "productExternalNumber")]
[XmlElement(ElementName = "ProductExternalNumber")]
public int? ProductExternalNumber { get; set; }
[JsonIgnore]
[XmlElement(ElementName = "ProductExternalType")]
public int? ProductExternalType { get; set; }
[JsonProperty(PropertyName = "id")]
[XmlElement(ElementName = "Id")]
public int? DefaultStageId { get; set; }
[JsonProperty(PropertyName = "unitName")]
[XmlElement(ElementName = "UnitName")]
public string UnitName { get; set; }
[JsonProperty(PropertyName = "sourceIntegrationCode")]
[XmlElement(ElementName = "SourceIntegrationCode")]
public string SourceIntegrationCode { get; set; }
[JsonProperty(PropertyName = "externalStorehouseId")]
[XmlElement(ElementName = "ExternalStorehouseId")]
public string ExternalStorehouseId { get; set; }
}
Мой JSON после сериализации:
{"name": "Bruynzeel Twin Felt Tip Flamastry 20szt", "code": "BS-2020K20B", "ean": "2010000000090", "description": "", "value1": "", "value2": "", "productExternalNumber ": 9," id ": 0," unitName ":" szt. "," sourceIntegrationCode ":" XL "," externalStorehouseId ":" 2 "}
Я пытался использовать Postman для отправки сообщения Postи это сработало.
Полная ошибка
Newtonsoft.Json.JsonReaderException: неожиданный символ, обнаруженный при разборе значения: A. Путь '', строка 0, позиция 0. в Newtonsoft.Json.JsonTextReader.) на Newtonsoft.Json.JsonSerializer.DeserializeInternal (читатель JsonReader, тип objectType) в Newtonsoft.Json.JsonConvert.DeserializeObject (строковое значение, тип Type, параметры JsonSerializerSettings) в Newtonsoft.Json.JsonConvert.DeserializeObject [T] (строковое значение, параметры JsonSerializerSoft).JsonConvert.DeserializeObject [T] (строковое значение) в Y.PluginPackingIntegration.Controllers.BaseIntegrationController. <> C__DisplayClass9_0.b__0 () в System.Threading.Tasks.Task`1.InnerInvoke () в System.ThreadTasTas.Tas.Execute ()