[英]@FormParam doesn't work with 'Content-Type': 'application/json'
The client side will send the request in json format. 客户端将以json格式发送请求。 However, it looks like the value can't be got by
@FormParam
annotation. 但是,看起来
@FormParam
批注无法获得该值。 I tried to change the @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
but it didn't work. 我试图更改
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
但是它不起作用。
Which kind of change shall I make on JAVA side to receive the data correctly? 我应该在JAVA端进行哪种更改才能正确接收数据?
For example, JSON data is 例如,JSON数据是
var postData = {
'uipath': 'xxx\abc\location1',
'value': 'Hello World!'
};
The JAX-RS method is JAX-RS方法是
@POST
@Path(value = "/receive")
public Object getValueFromUIPath(@Context UriInfo uriInfo,
@FormParam("uipath") String uiPath,
@FormParam("value") String value) {
...
}
for your information 供你参考
and coming to the answer , you are creating json object 并回答,您正在创建json对象
{
'uipath': 'xxx\abc\location1',
'value': 'Hello World!'
}
however you are suppose to consume two string fields, not an object. 但是,您假设要使用两个字符串字段,而不是一个对象。 you have two options, whether consume object have two fields
uipath
and value
, or send simple value rather then json object. 您有两个选择,无论消费对象具有两个字段
uipath
和value
,还是发送简单值而不是json对象。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.