2017-02-25 211 views
0

我試圖通過在下面的函數的參數XLIFF內容,我得到錯誤:請求實體的媒體類型「應用程序/ XML」不支持此資源

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

{ "message": "The request entity's media type 'application/xml' is not supported for this resource.", "exceptionMessage": "No MediaTypeFormatter is available to read an object of type 'xliff' from content with media type 'application/xml'.", "exceptionType": "System.Net.Http.UnsupportedMediaTypeException", "stackTrace": " at System.Net.Http.HttpContentExtensions.ReadAsAsync[T](HttpContent content, Type type, IEnumerable 1 formatters, IFormatterLogger formatterLogger, CancellationToken cancellationToken)\r\n at System.Net.Http.HttpContentExtensions.ReadAsAsync(HttpContent content, Type type, IEnumerable 1 formatters, IFormatterLogger formatterLogger, CancellationToken cancellationToken)\r\n at System.Web.Http.ModelBinding.FormatterParameterBinding.ReadContentAsync(HttpRequestMessage request, Type type, IEnumerable`1 formatters, 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 
    } 
+0

什麼是您的請求內容類型 – levent

+0

xliff格式是application/xliff + xml還是application/xliff + xml – SmartestVEGA

回答

0

當我檢查默認XML的媒體文件格式,它看起來像..

enter image description here

我不知道會發生什麼,如果添加手冊。可能需要定製序列化..

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