【发布时间】:2021-07-30 10:37:44
【问题描述】:
您好,我一直在努力解决我的问题,以至于不得不请教其他人。
我正在使用一些 API,我想通过 Postman 使用 POST 方法创建资源。要创建该资源,我必须将 kubeconfig 文件附加到 POST 请求。这个资源需要有名称、描述,当然还有配置文件。所以我填写了必填字段:
但我收到响应“错误请求”:
Invalid Input:: Does not match pattern '^([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9]$'
看起来我不明白如何以这种方式上传文件,因为我的请求正文看起来像:
Request Body
metadata: "{"name": "edge01", "description": "Edge k8s cluster"}"
file: undefine
在 API 文档中,我们可以发现请求正文应该是这样的:
Request body multipart/form-data
metadata
object
file
string($binary)
下面的整个 POST 条目:
Network
Request Headers
Accept: */*
Postman-Token: 8857f718-bb05-404c-865a-51ee3c0abe6f
Host: <Hidden_IP>:30461
Accept-Encoding: gzip, deflate, br
Connection: keep-alive
Content-Type: multipart/form-data; boundary=--------------------------175308278007362265143565
Content-Length: 3518
Request Body
metadata: "{"name": "edge01", "description": "Edge k8s cluster"}"
file: undefined
Response Headers
Content-Type: text/plain; charset=utf-8
X-Content-Type-Options: nosniff
Date: Fri, 30 Jul 2021 10:19:58 GMT
Content-Length: 84
Response Body
Invalid Input:: Does not match pattern '^([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9]$'↵
我找不到有关上述响应的任何信息。
如果有人需要更多信息,请发表评论。这个字符串($binary) 很有趣,但我不明白它的含义,并且在 POSTMAN 上下文中找不到任何信息。
这是一段 API yaml:
/cluster-providers/{cluster-providers-name}/clusters:
parameters:
- $ref: '#/components/parameters/clusterProviderName'
post:
tags:
- Clusters
summary: Add Cluster
description: Add a new `cluster`
operationId: addClusterToClusterProvider
responses:
'201':
description: Created
content:
application/json: # operation response mime type
schema:
$ref: '#/components/schemas/Metadata'
'400':
description: Bad Request
'404':
description: Not Found
'409':
description: Conflict
'422':
description: Unprocessable Entity
'500':
description: Internal Server Error
requestBody:
content:
multipart/form-data: # Media type
schema: # Request payload
$ref: '#/components/schemas/AppData'
【问题讨论】:
标签: postman http-post multipartform-data