Forum Discussion

ErnieWegrecki's avatar
ErnieWegrecki
Frequent Visitor
4 months ago

Request Body Value with an '&'

On SwaggerHub pages, I am attempting to return an authorization token.  The password parameter within the Request Body (x-www-form-urlencoded) will not work when an ampersand (&) is part of the value.  It works fine using Postman or Visual Studio Code, but does not work within the Swagger pages.  I have even used the encoding: password: allowReserved : true, but to no avail.  Anyone else have this issue or a workaround?

  • Maximilian's avatar
    Maximilian
    New Contributor

    The issue you're encountering on SwaggerHub with the password containing an ampersand (&) character within the x-www-form-urlencoded request body is likely related to how special characters are handled in URL encoding within Swagger's UI. The ampersand is a reserved character in URLs, and improper encoding can cause issues where it might be treated as a delimiter instead of part of the password string.

    Here's a breakdown of potential solutions and workarounds:

    1. Ensure Proper URL Encoding:

    • Ampersands (&) must be URL-encoded as %26. While SwaggerHub may not always handle encoding correctly by default, you can manually encode the password field to ensure that the ampersand is treated as a literal character and not a separator.
    • For example, if your password is pass&word123, you should encode it as pass%26word123.