Skip to content

[fix] application/xml body can not get from ctx.request.body #210

@chuantianc

Description

@chuantianc

Describe the bug

Node.js version:
v15.14.0
OS version:
macos monterey 12.5.1
Description:
I use the demo : https://github.com/koajs/koa-body#hello-world---quickstart to recive a application/xml request, but ctx.request.body is empty.

Actual behavior

image

Expected behavior

expected the same req content

Code to reproduce

req cmd:

curl --location --request POST 'http://127.0.0.1:3000' \
--header 'Content-Type: application/xml' \
--data-raw '<xml>
    <mch_id>123</mch_id>
    <nonce_str>adb</nonce_str>
    <sign>BIYTVI1123</sign>
</xml>'

server code(same as the example):

const Koa = require('koa');
const koaBody = require('koa-body');

const app = new Koa();

app.use(koaBody());
app.use(ctx => {
  ctx.body = `Request Body: ${JSON.stringify(ctx.request.body)}`;
});

app.listen(3000);

Checklist

  • [ yes] I have searched through GitHub issues for similar issues.
  • [ yes] I have completely read through the README and documentation.
  • [ yes] I have tested my code with the latest version of Node.js and this package and confirmed it is still not working.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions