【问题标题】:Post request with array使用数组发布请求
【发布时间】:2019-11-10 23:38:09
【问题描述】:

我想在 javascript 应用程序上使用邮递员测试我的 Web API。

我有以下招摇。

"/attachment/erase": {
      "post": {
        "summary": "Erase ",
        "consumes": [
          "application/json"
        ],
        "produces": [
          "application/json"
        ],
        "parameters": [
          {
            "name": "folder",
            "in": "query",
            "type": "string",
            "description": "folder('s) detail",
            "required": true
          },
          {
            "name": "type",
            "in": "query",
            "type": "string",
            "description": "ABC or BCD",
            "required": true
          },
          {
            "name": "body",
            "in": "body",
            "required": true,
            "schema": {
              "type": "object",
              "required": ["files"],
              "properties": {
                "attachments": {
                  "type": "array",
                  "items": {
                    "type": "string"
                  }
                }
              }
            },
            "description": "The file(s) to delete"
          }
        ],
        "responses": {
          "200": {
            "description": "file(s) erased."
          }
        }
      }
    }

所以我发送以下请求:

具有以下主体:

作为回报,我收到错误 415。

我做错了什么?

【问题讨论】:

    标签: javascript arrays post swagger postman


    【解决方案1】:

    当 API 期待 application/json 时,您正在发送 x-www-form-urlencoded

    【讨论】:

    • ups,初学者错误。谢谢,它现在可以工作了:)
    【解决方案2】:

    如何传递一个form-data参数文件,请参考图片

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-09-12
      • 2014-06-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多