首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用Jersey更改状态Openhab项?

如何使用Jersey更改状态Openhab项?
EN

Stack Overflow用户
提问于 2018-06-03 03:19:34
回答 1查看 42关注 0票数 0

如何使用Jersey更改状态Openhab项?

源代码:

代码语言:javascript
复制
ClientConfig clientConfig = new ClientConfig();
Client client = ClientBuilder.newClient(clientConfig);
WebTarget webTarget = client.target("http://demo.openhab.org:8080/rest");
WebTarget resourceWebTarget = webTarget.path("things");
Form form =new Form();
if (item.getState().equals("ON"))
   form.param("state", "OFF");
else
   form.param("state", "ON");
response = 
webTarget.path("items").path("Light_GF_Corridor_Ceiling").request()
.header("Content-Type", "text/plain")
.header("Accept", "application/json")        
.post(Entity.entity(form,MediaType.APPLICATION_JSON),Response.class);
System.out.println("Status Info Response " + response.getStatusInfo());

输出:状态信息响应不支持的媒体类型

EN

回答 1

Stack Overflow用户

发布于 2018-06-03 10:27:50

Form不是用来和application/json一起使用的(它是用来用application/x-www-form-urlencoded的)。对于JSON,您应该使用POJOs、POJOS集合或String。如果要发送POJO集合,则需要将其包装在GenericEntity中。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50660360

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档