[英]Californium Framework CoAP and PUT request
I am trying to do a request to coap server (er-rest-example) using Californium.我正在尝试使用 Californium 向 coap 服务器(er-rest-example)发出请求。 I succesfully do a POST request.
我成功地做了一个 POST 请求。 But with PUT I am getting a BAD REQUEST, I try using this URLs in url:
但是使用 PUT 我收到了一个错误的请求,我尝试在 url 中使用这个 URL:
coap://[aaaa::c30c:0000:0000:0002]:5683/actuators/leds
coap://[aaaa::c30c:0000:0000:0002]:5683/actuators/leds?
coap://[aaaa::c30c:0000:0000:0002]:5683/actuators/leds?color=r
But with no one get success.但没有人获得成功。 What I am doing wrong?.
我做错了什么?
This is my simple script:这是我的简单脚本:
package coap_client;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Arrays;
import java.util.Timer;
import java.util.TimerTask;
import org.eclipse.californium.core.CoapClient;
import org.eclipse.californium.core.CoapResponse;
import org.eclipse.californium.core.coap.MediaTypeRegistry;
public class cliente {
public static void main(String[] args) throws Exception {
Timer timer;
timer = new Timer();
TimerTask task = new TimerTask(){
@Override
public void run(){
String url="coap://[aaaa::c30c:0000:0000:0002]:5683/actuators/leds";
URI uri= null;
try {
uri = new URI(url);
} catch (URISyntaxException e) {
e.printStackTrace();
}
CoapClient client = new CoapClient(uri);
CoapResponse response = client.put("color=r",MediaTypeRegistry.TEXT_PLAIN);
System.out.println(response.isSuccess());
if (response!=null) {
byte[] myreponse=response.getPayload();
String respuesta2 = new String(myreponse);
System.out.println(respuesta2);
}
}
};
timer.schedule(task, 10,10*1000);
}
}
In Contiki er-rest-example
, see the POST/PUT
handler( 1 ) for the LED CoAP resource.在 Contiki
er-rest-example
,请参阅 LED CoAP 资源的POST/PUT
处理程序 ( 1 )。 It expects a mode
param without which you will get a BAD_REQUEST as response.它需要一个
mode
参数,没有它你会得到一个 BAD_REQUEST 作为响应。 I assume that has to go in the request body.我认为必须进入请求正文。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.