にmultipartされていません。 POSTサービスのためのコードは、「アプリケーション/ x-www-form-urlencodedで」私はコンテンツタイプを使用してこのサービスにデータを掲載してい現在の要求は、私が闊歩APIから春のREST Webサービスを生成した
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.SpringCodegen", date = "2016-10-24T09:36:32.738Z")
@Api(value = "addUser", description = "the addUser API")
public interface AddUserApi {
@ApiOperation(value = "Add an additional user", notes = "This service is used to add and additional user to the list of users.", response = Void.class, tags={ })
@ApiResponses(value = {
@ApiResponse(code = 200, message = "OK", response = Void.class),
@ApiResponse(code = 200, message = "Unexpected error", response = Void.class) })
@RequestMapping(value = "/addUser",
produces = { "application/json" },
consumes = { "application/x-www-form-urlencoded" },
method = RequestMethod.POST)
ResponseEntity<Void> addUserPost(
@ApiParam(value = "Unique id of the user to be added.", required=true) @RequestPart(value="userId", required=true) Integer userId,
@ApiParam(value = "Name of the user to be added.", required=true) @RequestPart(value="name", required=true) String name,
@ApiParam(value = "Profession of the user to be added.", required=true) @RequestPart(value="profession", required=true) String profession);
}
以下の通りです。しかし、私が直面している問題は、投稿時に以下のレスポンスとしてエラーJSONが発生していることです。
{
"timestamp": 1477401894250,
"status": 500,
"error": "Internal Server Error",
"exception": "org.springframework.web.multipart.MultipartException",
"message": "The current request is not a multipart request",
"path": "/UserManagement/rest/UserService/addUser"
}
私の知るところによれば、マルチパートは、フォームからファイルをアップロードするときにのみ必要です。私はファイルをアップロードしていません。私は検索し、すべての結果はファイルのアップロードに基づいています。私のすごいYAMLは以下の通りです。
swagger: '2.0'
info:
version: 1.0.0
title: Extended User Management API
description: >-
This is communicate with an extended user management webservice to test the swagger API for learning
schemes:
- http
basePath: /UserManagement/rest/UserService
host: '127.0.0.1:8089'
produces:
- application/json
paths:
/users:
get:
responses:
'200':
description: An array of users
schema:
type: array
items:
$ref: '#/definitions/User'
default:
description: Unexpected error
schema:
$ref: '#/definitions/Error'
/addUser:
post:
summary: Add an additional user
description: This service is used to add and additional user to the list of users.
produces:
- application/json
consumes:
- application/x-www-form-urlencoded
parameters:
- name: user_id
in: query
description: Unique id of the user to be added.
required: true
type: integer
format: int32
- name: name
in: query
description: Name of the user to be added.
required: true
type: string
- name: profession
in: query
description: Profession of the user to be added.
required: true
type: string
responses:
'200':
description: OK
default:
description: Unexpected error
schema:
$ref: '#/definitions/Error'
definitions:
User:
type: object
properties:
user_id:
type: integer
format: int32
description: This is unique id that is assigned to each user.
name:
type: string
description: This is the name of the user
profession:
type: string
description: This is the profession that the user holds
Error:
type: object
properties:
code:
type: integer
format: int32
message:
type: string
fields:
type: string
誰かが私を助けて、私がこの問題に直面している理由と解決方法を教えてください。問題を分析するために他の詳細が必要な場合はお知らせください。
{
"Accept": "application/json"
}
編集を次のように
リクエストヘッダは以下のとおりです。私は消費への "アプリケーション/ JSONを" 変更しようとしたと
{
"timestamp": 1477464487595,
"status": 415,
"error": "Unsupported Media Type",
"exception": "org.springframework.web.HttpMediaTypeNotSupportedException",
"message": "Content type 'application/x-www-form-urlencoded' not supported",
"path": "/UserManagement/rest/UserService/addUser"
}
の下に与えられたとして、私は応答を得た
リクエストヘッダは
以下に示します。
JSONデータ型を受け入れるために、以下にそれを変更することができ、消費が含まれていますリクエストヘッダーを貼り付けますか? – Waqas
あなたの全体のリクエストを追加します – kuhajeyan