简体   繁体   English

POST 请求中缺少 header “内容类型” swagger node.js

[英]missing header "content-type" on POST request swagger node.js

Sending a POST request with an body in Swagger , nothing arrives in request... I think the problem is because it doesn't have the header " content-type "发送带有Swagger正文的POST请求,请求中没有任何内容...我认为问题是因为它没有 header “内容类型

Testing the same request in postman arrives normally(why has the header).postman中测试相同的请求正常到达(为什么有标头)。

stopped sending the header when I added authorization in swaggerOptions, specifically " openapi ", " schemes " and " security "当我在 swaggerOptions 中添加授权时,停止发送 header,特别是“ openapi ”、“ scheme ”和“ security

swaggerOptions.json swaggerOptions.json

const swaggerOptions = {
    definition: {  
        openapi: '3.0.0',  
        info: {            
            version: "1.0.0",
            title: "Diniz API",
            description: "Rest API Diniz",
            servers: ['http://localhost:5000']
        },
        components: {
            securitySchemes: {
                bearerAuth: {
                    type: 'apiKey',
                    name: 'Authorization',
                    scheme: 'bearer',
                    in: 'header',
                },
            }
        },
        security: [{ 
            bearerAuth: [], 
        }],
    },
    apis: ['routes/*.js']
}

In your /signup annotations, replace the parameters section with the following requestBody section:在您的/signup注释中,将parameters部分替换为以下requestBody部分:

*      ...
*      summary: Create new account
*
*      requestBody:
*        required: true
*        content:
*          application/json:
*            schema:
*              type: object
*              required:
*                - name
*                - email
*                - ...   # add the rest of the required properties
*              properties:
*                name:
*                  type: string
*                ...     # add the rest of the properties

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在node.js中设置Content-Type标头 - How to set Content-Type header in node.js Post查询ajax中的Content-Type。 Node.js - Content-Type in Post query ajax. Node.js 使用 node.js 发送 Content-Type: application/json post - send Content-Type: application/json post with node.js 如何使用node.js在Twilio中修复无效的内容类型标头? - How do I fix an invalid content-type header in Twilio using node.js? 如何使用Node原生的请求承诺进行XML正文/内容类型标头的POST? - How to make a POST with XML body/content-type header using request promise native in Node? Node.js Express:回显POST正文,而不管其Content-Type? - Node.js Express: echo the POST body regardless of its Content-Type? 芝麻/码头服务器为node.js http获取请求响应的内容类型错误 - sesame/jetty server responding wrong content-type for a node.js http get request 如何在node.js中读取Content-Type:application / octet-stream请求 - How to read Content-Type: application/octet-stream request in node.js 如何在node.js请求中为multipart / form-data设置Content-Type - How to set Content-Type for the multipart/form-data in node.js request 节点/请求错误:“处理POST请求:无内容类型” - Node/Request Error: “Processing POST Request: No Content-Type”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM