【问题标题】:Parameter dont have value in webapi参数在 web api 中没有值
【发布时间】:2017-02-28 07:33:24
【问题描述】:

我正在尝试通过 swagger 调用服务,方法是传递 XML 格式的参数。

方法在命中,但传入的参数为空

表示“xlff”为空白。你知道我在做什么错吗

/// <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="xlf">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 xlff)
    {
        return Content(HttpStatusCode.BadRequest, "Any object");
    }



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

【问题讨论】:

  • 客户端代码也很有用
  • 我正在使用 swagger 为什么需要客户端?
  • 这可能是因为无法反序列化您发送的 XML。您是否检查了xliff 是否与您发送的 XML 模式兼容?
  • 所以显示你如何调用这个 api。或者你在招摇中的定义
  • 如何检查?

标签: c# .net asp.net-web-api swagger


【解决方案1】:

您的参数内容类型是 application/json,但您发送的是 xml。您应该将内容类型更改为 application/xml。

【讨论】:

  • 我将如何改变这个?
  • 来自 swagger UI。在您的请求 xml 下方,您有“参数请求类型”下拉菜单
  • 我在下拉列表中没有 xml
  • 您是否在 WebApiConfig 中禁用了 xml 格式化程序?
  • 不知道是否添加了对xml的支持,在哪里查看?
猜你喜欢
  • 2023-04-06
  • 1970-01-01
  • 2016-09-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-08-06
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多