如何使用Jersey更改状态Openhab项?
源代码:
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());输出:状态信息响应不支持的媒体类型
发布于 2018-06-03 10:27:50
Form不是用来和application/json一起使用的(它是用来用application/x-www-form-urlencoded的)。对于JSON,您应该使用POJOs、POJOS集合或String。如果要发送POJO集合,则需要将其包装在GenericEntity中。
https://stackoverflow.com/questions/50660360
复制相似问题