[英]How can I send put request to backend through ejs template without using form?
[英]how can I send request body parameter through put Method with swagger-client
我正在使用swagger-client。 这是客户端的npm库模块。 但是我有问题 在服务器端,我正在使用Express。
即使我尝试使用put方法发送主体参数,express也不接受参数。 只能达到路径参数或查询参数。 那没问题。
这是代码和夸张的json。
■json中的请求路径。
"/test/{hogehoge}/sample": {
"put": {
"summary": "summary",
"description": "description",
"tags": [
"Sample"
],
"operationId": "operationId",
"parameters": [
{
"name": "path",
"in": "path",
"description": "path description",
"required": true,
"type": "integer"
},
{
"name": "body",
"in": "body",
"description": "body",
"required": true,
"schema": {
"$ref": "#/definitions/bodySchema"
}
}
],
■请求路径方案放在上面的方法中。
"bodySchema": {
"type": "object",
"properties": {
"bodySchemaVersion": {
"type": "string",
"description": "bodySchema version"
}
}
},
■快递日志
parameter:
{ query: {},
path:
{ param1: 'param1',
param2: 'param2' },
body: {} } } ← body that it should be bodySchema param.
■客户端提示
import Swagger from 'swagger-client';
import swaggerJson from '@/assets/swagger/swagger.json';
....
// opts include
// { bodySchema: { bodySchemaVersion: 'string text' } }
await this.swagger.client.apis[tagName][funcName](_opts);
我解决了这个问题。
this.swagger = new Swagger({
spec: json,
usePromise: true,
requestInterceptor(req) {
req.headers['Content-Type'] = 'application/json'; // I've add this line.
return req
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.