send-request url encoded - does the policy automatically url encode the body or does it have to be url encoded ?

Martin Kallukalam 335 Reputation points
2024-08-31T16:57:03.04+00:00

When I am using send-request policy and specify header x-www-form-urlencoded, is the policy expecting that the set-body (body) be set in url encoded format OR the policy will automatically do it for you?
EG: I want to pass body var1=test?test

<send-request mode="new" response-variable-name="foobar" timeout="20" ignore-error="true"> <set-url>https://www.foo.com</set-url> <set-method>POST</set-method> <set-header name="Content-Type" exists-action="override"> <value>application/x-www-form-urlencoded</value> </set-header> <set-body>See Question Below</set-body>
</send-request> Question: Does set-body have to be URL encoded (var1%3Dtest%3Ftest) OR non URL encoded "var1=test?test")

Azure API Management
Azure API Management
An Azure service that provides a hybrid, multi-cloud management platform for APIs.
2,074 questions
0 comments No comments
{count} votes

Accepted answer
  1. JananiRamesh-MSFT 26,546 Reputation points
    2024-09-04T16:55:00.0866667+00:00

    @Martin Kallukalam Thanks for getting back, The send-request policy does not automatically encode the body in URL-encoded format when the header application/x-www-form-urlencoded is specified. You need to manually encode the body in URL-encoded format using the set-body policy.

    The '=' character does not need to be URL encoded because it is a reserved character used to separate keys and values in the query string format. When forming a URL-encoded body, the '=' character is used to assign values to keys, and it is understood by the server as part of the key-value pair structure.

    do let me know incase of further queries, I would be happy to assist you.

    1 person found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Vahid Ghafarpour 21,085 Reputation points
    2024-08-31T21:25:46.55+00:00

    Thanks for posting your question in the Microsoft Q&A forum.

    When using the send-request policy with the Content-Type header set to application/x-www-form-urlencoded, you need to manually URL encode the body content. The policy does not automatically encode the body for you.

    ** Please don't forget to close up the thread here by upvoting and accept it as an answer if it is helpful **

    1 person found this answer helpful.

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.