我想生成 PUT 请求。我已成功生成 GET 请求以从 CoRE 资源目录获取数据,但无法使用 xml 有效负载生成 PUT 请求。我们将非常感谢您的帮助。 以下是我的代码
function PutReq(){
setTimeout(function() {
var request2 = new CoAPRequest();
var payload = '<?xml version="1.0" encoding="UTF-8"?><te:lightingSceneRootType xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"xmlns:te="http://www.baas-itea3.eu/temperature"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><lightingSceneName>Off</lightingSceneName></te:lightingSceneRootType>';
alert(payload);
request2.open('PUT', wLink , true);
request2.onload = function () {
var res2 = request2.responseText;
alert(res2);
};
request2.send();
}, 2000);
}
wLink 是我在其中放置 url 的变量。我正在使用此延迟函数,因为我正在从第一个函数获取链接,并且我需要延迟运行此请求,以便我可以从第一个函数获取响应。 问题是,如何使用 put 请求发送有效负载。请指导我。谢谢
最佳答案
我认为您只需将payload
传递给send
request2.send(payload);
关于javascript - 使用 CoAP 向 CoRE 资源目录发送 PUT 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39000113/