Skip to content

Payload for "application/x-www-form-urlencoded" is actually for "multipart/form-data" #1441

Open
@soulchild

Description

@soulchild

I have an OpenAPI specification with a contentType of application/x-www-form-urlencoded:

"/foo": {
  "post": {
    "requestBody": {
      "content": {
        "application/x-www-form-urlencoded": {
          "schema": {
            "$ref": "#/someSchema"
          }
        }
      }
    }
  }
}

This library creates POST data using FormData which ends up being suitable for a contentType of multipart/form-data, not application/x-www-form-urlencoded.

In other words, instead of something like:

parameter1=value1&parameter2=value2

it generates a base64-encoded payload, which decodes to:

----------------------------037807260368578567993227
Content-Disposition: form-data; name="parameter1"

value1
--------------

I believe the FormData needs to be passed through URLSearchParams() to generate a payload suitable for application/x-www-form-urlencoded:

const form = new FormData();
form.append('parameter1', 'value1');
form.append('parameter2', 'value2');
console.log(new URLSearchParams(form).toString());

// 'parameter1=value1&parameter2=value2'

Or am I missing something here? Thanks! 😄

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions