Azure Logic App:如何制作 x-www-form-encoded?

Azure Logic App: how to make a x-www-form-encoded?

我正在尝试使用 Content-Type x-www-form-urlencoded 发出请求,它在邮递员中完美运行但在 Azure 逻辑应用程序中不起作用我收到缺少参数的错误请求响应,就像我不会发送任何东西一样。

我正在使用 Http 操作。

body值是param1=value1¶m2=value2,但我试过其他格式

首先 body 需要:

{  param1=value1&param2=value2 }

(即用 {} 包围)

也就是说,value1 和 value2 应该 url 编码。如果它们是一个简单的字符串(例如 a_b),那么这将按原样找到,但如果是例如 https://a.b,则应将其转换为 https%3A%2F%2Fa.b

我发现最简单的方法是使用 https://www.urlencoder.org/ 进行转换。分别转换每个参数并将转换后的值代替原始值。

回答这个问题,因为我今天需要自己打这样的电话。 正如 Assaf 上面提到的,请求确实必须经过 urlEncoded,而且很多时候你想要编写实际的消息有效负载。

此外,确保在 HTTP 操作中添加 Content-Type header 值为 application/x-www-form-urlencoded

因此,您可以使用以下代码组合得到urlEncoded的变量:

concat('token=', **encodeUriComponent**(body('ApplicationToken')?['value']),'&user=', **encodeUriComponent**(body('UserToken')?['value']),'&title=Stock+Order+Status+Changed&message=to+do')

使用 concat 函数时(在组合中),不需要花括号。

Try out the below solution . Its working for me .

concat(
'grant_type=',encodeUriComponent('authorization_code'),
'&client_id=',encodeUriComponent('xxx'),
'&client_secret=',encodeUriComponent('xxx'),
'&redirect_uri=',encodeUriComponent('xxx'),
'&scope=',encodeUriComponent('xxx'),
'&code=',encodeUriComponent(triggerOutputs()['relativePathParameters']['code'])).

Here code is dynamic parameter coming from the previous flow's query parameter.

NOTE : **Do not forget to specify in header as Content-Type ->>>> application/x-www-form-urlencoded**
HTTP Method: POST
URI : https://xxx/oauth2/token

在 Headers 部分,添加以下 content-type:

Content-Type: application/x-www-form-urlencoded

并在 Body 中添加:

grant_type=xxx&client_id=xxx&resource=xxx&client_secret=xxx