Я использую Alamofire в быстрой передаче HTTP-запроса/сообщения на сервер. Ниже приведен код, который я использовал в swift.Как установить параметры сообщения при использовании Alamofire в swift
Alamofire.request(.POST, "http://localhost:8080/hello", headers: [ACCESS_TOKEN:token, "Content-Type":"application/x-www-form-urlencoded" ],
parameters:["friend_id" : friendId, "skill_id" : skillId]).response(completionHandler: {
(request, response, data, error) in
print(request)
print(response)
print(data)
print(error)
})
Ниже приведен код, определенный в стороне сервера:
@POST
@Path("/hello")
@Produces(MediaType.APPLICATION_JSON)
public Response nominateSkill(@Context HttpServletRequest request, @FormParam("friend_id") long friendId, @FormParam("skill_id") int skillId) {
// ...
}
Когда я бегу быстрый код, у меня всегда ниже сообщение об ошибке в стороне сервера:
A servlet request to the URI http://localhost:8080/hello contains form parameters in the request body but the request body has been consumed by the servlet or a servlet filter accessing the request parameters. Only resource methods using @FormParam will work as expected. Resource methods consuming the request body by other means will not work as expected.
Я думаю, проблема будет связана с быстрым кодом, который не задал параметр правильно. Но я не знаю, как правильно их установить?