【发布时间】:2017-07-16 07:28:45
【问题描述】:
我正在尝试在以下函数的参数中传递 XLIFF 内容,但出现错误:
public IHttpActionResult ProcessSmartlingTranslation([FromBody]xliff xliff)
{
return Content(HttpStatusCode.BadRequest, "Any object");
}
{ "message": "请求实体的媒体类型 'application/xml' 是 此资源不支持。", "exceptionMessage": "否 MediaTypeFormatter 可用于从 媒体类型为“application/xml”的内容。”、“exceptionType”: “System.Net.Http.UnsupportedMediaTypeException”,“stackTrace”:“在 System.Net.Http.HttpContentExtensions.ReadAsAsync[T](HttpContent 内容,类型类型,IEnumerable
1 formatters, IFormatterLogger formatterLogger, CancellationToken cancellationToken)\r\n at System.Net.Http.HttpContentExtensions.ReadAsAsync(HttpContent content, Type type, IEnumerable1 格式化程序,IFormatterLogger formatterLogger, CancellationToken cancelToken)\r\n 在 System.Web.Http.ModelBinding.FormatterParameterBinding.ReadContentAsync(HttpRequestMessage 请求,类型类型,IEnumerable`1 格式化程序,IFormatterLogger formatterLogger, CancellationToken cancelToken)" }
我将如何解决这个问题?
完整代码如下:
// <summary>
/// XliffModel created
/// </summary>
public class xliff
{
/// <summary>
/// file getter setter method
/// </summary>
public string file { get; set; }
/// <summary>
/// body getter setter method
/// </summary>
public string body { get; set; }
}
/// <summary>
/// Web api for smartling translation processing
/// </summary>
/// <seealso cref="ApiController" />
public class SmartlingController : ApiController
{
#region Public Methods
/// <summary>
/// Get or insert blog comments which is approved based on blogs
/// </summary>
/// <remarks> Get or insert blog comments which is approved based on blogs</remarks>
/// <param name="message">The comment.</param>
/// <response code="200">Get approved blog comments</response>
/// <response code="404">Not found</response>
/// <returns>IHttpActionResult</returns>
[Route("api/smartling/ProcessSmartlingTranslation")]
[VersionedRoute("", 1)]
[ResponseType(typeof(HttpResponseMessage))]
[HttpPost]
public IHttpActionResult ProcessSmartlingTranslation([FromBody]xliff xlf)
{
return Content(HttpStatusCode.BadRequest, "Any object");
}
#endregion
}
【问题讨论】:
-
您的请求内容类型是什么
-
xliff 格式为 application/xliff+xml 或 application/xliff+xml
标签: c# .net xml api asp.net-web-api