简体   繁体   English

@FormParam不适用于“ Content-Type”:“ application / json”

[英]@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 供你参考

  1. use consumes annotaion 使用消耗注释
  2. json should be double quoted json应该用双引号引起来

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. 您有两个选择,无论消费对象具有两个字段uipathvalue ,还是发送简单值而不是json对象。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么@FormParam 不支持 content=type=application/json? - Why @FormParam does not support content=type=application/json? 在Content-Type中指定charset时,Jersey和@FormParam无法正常工作 - Jersey and @FormParam not working when charset is specified in the Content-Type 在 Spring 中读取 Content-Type 应用程序/json - Reading Content-Type application/json in Spring 没有为Content-Type定义解析器:application / json - No parser defined for Content-Type: application/json MVC-当自定义内容类型时接受JSON(不是application / json) - MVC - Accept JSON when content-type is custom (not application/json) 为什么日期转换在 Spring 中对内容类型为 json-patch 的请求不起作用? - Why won't the date conversion work in Spring on requests with content-type json-patch? RESTEasy:找不到内容类型应用程序/json 类型的编写器 - RESTEasy: Could not find writer for content-type application/json type 泽西岛:@Consumes在没有设置内容类型时不起作用 - Jersey: @Consumes doesn't quite work when content-type is not set PlayFramework使用content-type application / json返回BadRequest - PlayFramework returns BadRequest with content-type application/json JAVA-处理针对Content-Type的HttpClient请求:application / json - JAVA - Process HttpClient request for Content-Type: application/json
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM