如何使用 Azure Api 管理发送 post form-data 文件和数据?
How to send post form-data with file and data using Azure Api Management?
我想在 Azure API 管理上创建 post 请求,格式为 form-data。我必须将 body 中的文件和数据发送到 url 但不知道如何发送两者。
我从 postman 那里得到了 http 代码:
request in postman
我找不到发送包含文件和数据的 post 请求的方法。当我尝试使用两者之一发送时,我得到了回复:
HTTP/1.1 500 Erreur Interne de Servlet
cache-control: no-cache, no-store, max-age=0, must-revalidate
connection: close
content-language: fr
content-type: text/html;charset=utf-8
date: Thu, 16 Jul 2020 12:21:46 GMT
expires: 0
ocp-apim-trace-location: https://apimstuj2itdypxpozialwwt.blob.core.windows.net/apiinspectorcontainer/UcMgQhu6NisyHHuKEITNDw2-235?sv=2018-03-28&sr=b&sig=Eno9E9bzDcwFOC%2Brl88RY3%2Fq955Ly%2F6r1uyIO0eRwQM%3D&se=2020-07-17T12%3A21%3A45Z&sp=r&traceId=3a143ab6435b46d29e69b30eed34fd23
pragma: no-cache
strict-transport-security: max-age=31536000 ; includeSubDomains
transfer-encoding: chunked
vary: Origin
x-application-context: application
x-content-type-options: nosniff
x-frame-options: DENY
x-xss-protection: 1; mode=block
<!DOCTYPE html><html><head><title>Apache Tomcat/8.0.47 - Rapport d''erreur</title><style type="text/css">H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}.line {height: 1px; background-color: #525D76; border: none;}</style> </head><body><h1>Etat HTTP 500 - Request processing failed; nested exception is org.springframework.web.multipart.MultipartException: Could not parse multipart servlet request; nested exception is java.io.IOException: org.apache.tomcat.util.http.fileupload.FileUploadException: the request was rejected because no multipart boundary was found</h1><div class="line"></div><p><b>type</b> Rapport d''exception</p><p><b>message</b> <u>Request processing failed; nested exception is org.springframework.web.multipart.MultipartException: Could not parse multipart servlet request; nested exception is java.io.IOException: org.apache.tomcat.util.http.fileupload.FileUploadException: the request was rejected because no multipart boundary was found</u></p>
我试图在请求 header 和 body 中设置边界,但我遇到了同样的错误。我有以下 body:
Body content
OpenAPI v3 Azure 中的支持 API 管理包括对预览功能的修复和改进——例如,它启用 支持 multipart/form-data 内容类型.
在 OpenAPI 3.0 中,请求正文(包括表单数据)是使用 requestBody
关键字而不是 in: formData
参数定义的。
"paths": {
"/api/rmt-create-request": {
"post": {
"tags": [
"RMT APIs"
],
"description": "Return newly created request data",
"operationId": "create-new-rmt-request",
"requestBody": {
"content": {
"multipart/form-data": { // or "application/x-www-form-urlencoded" - depending on what you need
"schema": {
"type": "object",
"properties": {
"rootNodeName": {
"type": "string",
"description": "Root node class name for item"
}
}
}
}
}
}
}
}
}
更多细节,你可以参考这个article。
我想在 Azure API 管理上创建 post 请求,格式为 form-data。我必须将 body 中的文件和数据发送到 url 但不知道如何发送两者。
我从 postman 那里得到了 http 代码: request in postman
我找不到发送包含文件和数据的 post 请求的方法。当我尝试使用两者之一发送时,我得到了回复:
HTTP/1.1 500 Erreur Interne de Servlet
cache-control: no-cache, no-store, max-age=0, must-revalidate
connection: close
content-language: fr
content-type: text/html;charset=utf-8
date: Thu, 16 Jul 2020 12:21:46 GMT
expires: 0
ocp-apim-trace-location: https://apimstuj2itdypxpozialwwt.blob.core.windows.net/apiinspectorcontainer/UcMgQhu6NisyHHuKEITNDw2-235?sv=2018-03-28&sr=b&sig=Eno9E9bzDcwFOC%2Brl88RY3%2Fq955Ly%2F6r1uyIO0eRwQM%3D&se=2020-07-17T12%3A21%3A45Z&sp=r&traceId=3a143ab6435b46d29e69b30eed34fd23
pragma: no-cache
strict-transport-security: max-age=31536000 ; includeSubDomains
transfer-encoding: chunked
vary: Origin
x-application-context: application
x-content-type-options: nosniff
x-frame-options: DENY
x-xss-protection: 1; mode=block
<!DOCTYPE html><html><head><title>Apache Tomcat/8.0.47 - Rapport d''erreur</title><style type="text/css">H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}.line {height: 1px; background-color: #525D76; border: none;}</style> </head><body><h1>Etat HTTP 500 - Request processing failed; nested exception is org.springframework.web.multipart.MultipartException: Could not parse multipart servlet request; nested exception is java.io.IOException: org.apache.tomcat.util.http.fileupload.FileUploadException: the request was rejected because no multipart boundary was found</h1><div class="line"></div><p><b>type</b> Rapport d''exception</p><p><b>message</b> <u>Request processing failed; nested exception is org.springframework.web.multipart.MultipartException: Could not parse multipart servlet request; nested exception is java.io.IOException: org.apache.tomcat.util.http.fileupload.FileUploadException: the request was rejected because no multipart boundary was found</u></p>
我试图在请求 header 和 body 中设置边界,但我遇到了同样的错误。我有以下 body: Body content
OpenAPI v3 Azure 中的支持 API 管理包括对预览功能的修复和改进——例如,它启用 支持 multipart/form-data 内容类型.
在 OpenAPI 3.0 中,请求正文(包括表单数据)是使用 requestBody
关键字而不是 in: formData
参数定义的。
"paths": {
"/api/rmt-create-request": {
"post": {
"tags": [
"RMT APIs"
],
"description": "Return newly created request data",
"operationId": "create-new-rmt-request",
"requestBody": {
"content": {
"multipart/form-data": { // or "application/x-www-form-urlencoded" - depending on what you need
"schema": {
"type": "object",
"properties": {
"rootNodeName": {
"type": "string",
"description": "Root node class name for item"
}
}
}
}
}
}
}
}
}
更多细节,你可以参考这个article。