如何使用mulesoft将查询字符串传递给post请求

问题描述 投票:0回答:1

我是Mulesoft的新手,我正在尝试发送一些(四个)查询参数。使用SOAP UI A screen shot of what I tested进行测试时

我使用以下xml配置在mulesoft中复制了这个

<flow name="boxintegrationFlow1">
    <http:listener config-ref="HTTP_Listener_Configuration1" path="*" doc:name="HTTP"/>
    <logger message="Message: #[message.inboundProperties] Code: #[message.inboundProperties.'http.query.params'.code]" level="INFO" doc:name="Logger"/>
    <set-property propertyName="Content-Type" value="application/x-www-form-urlencoded" doc:name="Property"/>
    <set-variable variableName="QueryParameters" value="{'grant_type':'authorization_code', 'code':''#[message.inboundProperties.'http.query.params'.code]','client_id':'abc','client_secret':'xyz'}" doc:name="Variable" mimeType="application/x-www-form-urlencoded"/>
    <logger message="#[flowVars.QueryParameters]" level="INFO" doc:name="Logger"/>
    <set-payload value="#[flowVars.QueryParameters]" doc:name="PostQueryParameters"/>
    <http:request config-ref="getToken" path="/oauth2/token" method="POST" sendBodyMode="ALWAYS" doc:name="HTTP">
        <http:request-builder>
            <http:query-param paramName="grant_type" value="authorization_code"/>
            <http:query-param paramName="code" value="#[message.inboundProperties.'http.query.params'.code]"/>
            <http:query-param paramName="client_id" value="xyz"/>
            <http:query-param paramName="client_secret" value="abc"/>
        </http:request-builder>
        <http:success-status-code-validator values="400"/>
    </http:request>
    <logger message="Message: #[message.outboundProperties] " level="INFO" doc:name="Logger"/>
</flow>

执行此操作时出现错误“{”error“:”invalid_request“,”error_description“:”无效的grant_type参数或参数缺失“}”

我知道我们已将它作为查询字符串传递,但我无法弄清楚我该怎么做。

任何指针都表示赞赏。先感谢您!

http-post mule anypoint-studio
1个回答
0
投票

出现错误,您正在使用Mule OAuth provider或类似的东西。如果是这种情况,则问题不在于您将grant_type错误地添加为查询参数,而是您将客户端ID和机密作为参数发送。

您需要将您的客户端ID和密码作为基本身份验证标头发送。标题的格式应为Authorization: Basic NmJlXXXXXXXXXXc0NDZlYmFhNTgzMWQ0NDRhZmNjMmE6MzJkZTE1ZDZZZZZZZZZZZkFEOEJEQUU5QkNG

使用curl到本地运行的Mule OAuth提供程序的示例(使用资源用户名/密码授予类型):

curl -i -X POST -H "Content-Type: application/x-www-form-urlencoded" -H "Authorization: Basic NmJlXXXXXXXXXXc0NDZlYmFhNTgzMWQ0NDRhZmNjMmE6MzJkZTE1ZDZZZZZZZZZZZkFEOEJEQUU5QkNGMjc4RDYK" -d "grant_type=password&username=max&password=mule" "https://localhost:10101/external/access_token" -k
© www.soinside.com 2019 - 2024. All rights reserved.