繁体   English   中英

此资源不支持请求实体的媒体类型“application / xml”

[英]The request entity's media type 'application/xml' is not supported for this resource

我试图在以下函数的参数中传递XLIFF内容,我收到错误:

public IHttpActionResult ProcessSmartlingTranslation([FromBody]xliff xliff)
       {
           return Content(HttpStatusCode.BadRequest, "Any object");
       }

{“message”:“此资源不支持请求实体的媒体类型'application / xml'。”,“exceptionMessage”:“没有MediaTypeFormatter可用于从媒体类型'应用程序的内容中读取'xliff'类型的对象/ xml'。“,”exceptionType“:”System.Net.Http.UnsupportedMediaTypeException“,”stackTrace“:”at 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, IEnumerable在System.Web.Http.ModelBinding.FormatterParameterBinding的1 formatters, IFormatterLogger formatterLogger, CancellationToken cancellationToken)\\r\\n at System.Net.Http.HttpContentExtensions.ReadAsAsync(HttpContent content, Type type, IEnumerable 1格式化程序,IFormatterLogger formatterLogger,CancellationToken cancellationToken)\\ r \\ n中的formatterLogger,CancellationToken cancellationToken)\\ r \\ n .ReadContentAsync(HttpRequestMessage请求,类型类型,IEnumerable`1格式化程序,IFormatterLogger formatterLogger,CancellationToken cancellationToken)“}

我该如何解决这个问题?

完整代码如下:

// <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
   }

当我检查默认的xml媒体文件格式化程序时,它看起来像..

在此输入图像描述

如果添加手册,我不知道会发生什么。 可能需要自定义序列化..

            config.Formatters.XmlFormatter
            .SupportedMediaTypes
            .Add(new System.Net.Http.Headers.MediaTypeHeaderValue("application/xliff+xml"));

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM