【问题标题】:How to POST Content-Type application/x-www-form-urlencoded in Azure API Management body?如何在 Azure API 管理正文中发布 Content-Type application/x-www-form-urlencoded?
【发布时间】:2021-12-21 09:05:36
【问题描述】:

我一直在尝试找出一种在 Azure API 管理正文中发布 Content-Type application/x-www-form-urlencoded 的方法。

我已经设法让它在 Postman 中工作,因为它支持 x-www-form-urlencoded,但似乎无法在 API 管理中找到实现它的方法。无论我在哪里以及如何尝试在 API 管理中发布正文,它都会出现错误:解析请求时出错。预期格式:{ token: string,enrollDevice: bool }。在邮递员中,我可以使用格式为 {"token":"xxx","enrollDevice":xxx} 的 x-www-form-urlencoded 将值放入 POST 正文中,它可以工作!

如何使用 Azure API 管理在正文中发布所需的值?

如果您需要与问题相关的更多信息,我很乐意提供更多信息。我在这里先向您的帮助表示感谢! :)

【问题讨论】:

    标签: post jwt postman azure-api-management x-www-form-urlencoded


    【解决方案1】:

    我们可以添加一个策略来将标题设置为 name = “Content-Type”:

    <set-header name="Content-Type" exists-action="override">
        <value>application/json</value>
    </set-header>
    

    在入站策略部分添加所有格式,基本上我们有入站、出站、后端和错误策略。 检查 MS Docs 以设置 HTTP 标头。

    <inbound>
        <base />
        <set-header name="Content-Type" exists-action="override">
            <value> application/x-www-form-urlencoded</value>
        </set-header>
        <set-body template="liquid">{"QueryString": "123", "param1": "456"}</set-body>
        <set-body>@{ 
            JObject inBody = context.Request.Body.As<JObject>(); 
            return inBody.ToString(); 
        }</set-body>
    </inbound>
    

    还要确保正文的内容正确。

    【讨论】:

    • 这个答案解决了您的问题吗?
    猜你喜欢
    • 2019-02-04
    • 2019-06-14
    • 2013-11-10
    • 1970-01-01
    • 2019-10-26
    • 2017-09-22
    • 2017-07-19
    • 1970-01-01
    • 2019-02-20
    相关资源
    最近更新 更多