protected override void DoPut(CoapExchange exchange) { if (fActive) { Request request = exchange.Request; if (!request.HasOption(OptionType.ContentFormat) || request.GetFirstOption(OptionType.ContentFormat).IntValue != 0) { exchange.Respond(StatusCode.BadRequest, "Content Format"); return; } if (!request.HasOption(OptionType.IfMatch) || ByteCompare(request.GetFirstOption(OptionType.IfMatch).RawValue, _ifMatch) != 0) { exchange.Respond(StatusCode.BadRequest, "IfMatch"); return; } Response response = new Response(StatusCode.Content); response.AddETag(_ifMatch); response.ContentFormat = 0; response.Payload = content; exchange.Respond(response); } else { exchange.Respond(StatusCode.NotFound); } }
protected override void DoPost(CoapExchange exchange) { _WaitHandle.Set(); Response response = Response.CreateResponse(exchange.Request, StatusCode.Changed); exchange.Respond(response); }
protected override void DoPost(CoapExchange exchange) { Request request = exchange.Request; if (!request.HasOption(OptionType.ContentFormat) || request.GetFirstOption(OptionType.ContentFormat).IntValue != 0) { exchange.Respond(StatusCode.BadRequest, "Missing content format option"); return; } Response response; if (fActive) { response = new Response(StatusCode.Changed); content = request.Payload; } else { // Check what the payload is fActive = true; response = new Response(StatusCode.Created); response.LocationPath = "counter"; response.AddLocationQuery("first=1"); response.AddLocationQuery("second=2"); content = request.Payload; } exchange.Respond(response); }
protected override void DoPost(CoapExchange exchange) { try { Request request = exchange.Request; CBORObject obj = CBORObject.DecodeFromBytes(request.Payload); exchange.Accept(); String uri = obj[0].AsString(); byte[] key = obj[1].GetByteString(); List <SecurityContext> contexts = SecurityContextSet.AllContexts.FindByKid(key); if (contexts.Count == 0) { exchange.Respond(StatusCode.BadRequest, "No matching key identifier found"); return; } Codec.IMessageDecoder me = Spec.Default.NewMessageDecoder(obj[2].GetByteString()); Request newRequest = me.DecodeRequest(); newRequest.URI = new System.Uri(uri); newRequest.OscoapContext = contexts[0]; newRequest.Send(); Response response = newRequest.WaitForResponse(); exchange.Respond(response); } catch (Exception e) { exchange.Respond(StatusCode.BadRequest, e.ToString()); } }
protected override void DoPut(CoapExchange exchange) { Assert.AreEqual(_currentRequestText, exchange.Request.PayloadString); exchange.Accept(); _currentResponseText = ""; exchange.Respond(StatusCode.Changed); }
protected override void DoGet(CoapExchange exchange) { if ((exchange.Request.ContentFormat != 0) && (exchange.Request.ContentFormat != contentType)) { exchange.Respond(StatusCode.UnsupportedMediaType); return; } if (expire != null) { TimeSpan d = (DateTime)expire - DateTime.Now; if (d.TotalSeconds < 0) { content = null; } else { exchange.MaxAge = (int)d.TotalSeconds; } } if (content != null) { exchange.Respond(StatusCode.BadRequest); } else { exchange.Respond(StatusCode.Content, content); } }
protected override void DoPut(CoapExchange exchange) { Request req = exchange.Request; if (Attributes.Contains("ContentType")) { if (exchange.Request.ContentFormat != contentType) { exchange.Respond(StatusCode.BadRequest, "Mismatched content type"); return; } } if (req.HasOption(OptionType.MaxAge)) { if (exchange.Request.MaxAge > 0) { expire = DateTime.Now + new TimeSpan(0, (Int32)(exchange.Request.MaxAge / 60), (Int32)(exchange.Request.MaxAge % 60)); } else { expire = null; } } content = exchange.Request.Payload; Changed(); exchange.Respond(StatusCode.Changed); }
protected override void DoPost(CoapExchange exchange) { Request request = exchange.Request; bool processed = false; if ((request.ContentType == TlvConstant.CONTENT_TYPE_TLV)) { if (request.Payload != null) { using (TlvReader reader = new TlvReader(request.Payload)) { this.Deserialise(reader); processed = true; } } } if (processed) { Response response = Response.CreateResponse(exchange.Request, StatusCode.Changed); exchange.Respond(response); if (Updated != null) { Updated(this, null); } } else { Response response = Response.CreateResponse(exchange.Request, StatusCode.BadRequest); exchange.Respond(response); } }
protected override void DoPost(CoapExchange exchange) { string payload = exchange.Request.PayloadString; database.AddScan(payload); exchange.Respond("OK"); }
protected override void DoGet(CoapExchange exchange) { IEnumerable <string> queries = exchange.Request.UriQueries; exchange.MaxAge = 1; exchange.Respond(_content); }
protected override void DoPut(CoapExchange exchange) { switch (Name) { default: base.DoPut(exchange); return; case "7": { if (exchange.Request.IfNoneMatch) { Response res = new Response(StatusCode.PreconditionFailed); exchange.Respond(res); return; } Response response = new Response(StatusCode.Created) { ContentType = MediaType.TextPlain }; response.AddETag(new byte[] { 0x7b }); _payload = exchange.Request.Payload; exchange.Respond(response); break; } } }
protected override void DoGet(CoapExchange exchange) { st.Start(); string path = exchange.Request.UriQuery; string[] tokens = path.Split('/'); string deviceName = tokens[0]; string requstdatasize = tokens[1]; // Devices di = new Devices(eviceName,requstdatasize,"GET",null); _content = GenerateResponseData(Int32.Parse(requstdatasize)); if (_content != null) { exchange.Respond(_content); } else { String subtree = LinkFormat.Serialize(this, null); exchange.Respond(StatusCode.Content, subtree, MediaType.ApplicationLinkFormat); } st.Stop(); int responseSize = exchange.getResponseSize(); st.WriteLogServer("GET", deviceName, requstdatasize); }
protected override void DoPut(CoapExchange exchange) { int i = Int32.Parse(exchange.Request.PayloadString); _ctx.Sender.SequenceNumber = i - 1; exchange.Respond(StatusCode.Changed, "Next sequence number will be {0}", i); }
protected override void DoGet(CoapExchange exchange) { // Accept the request to promise the client this request will be acted. exchange.Accept(); // ... and then do nothing. Pretty mean... }
protected override void DoPost(CoapExchange exchange) { string payload = exchange.Request.PayloadString; if (payload != null) { EntidadPeticionSegura peticionSegura = JsonConvert.DeserializeObject <EntidadPeticionSegura>(payload); //Deserializamos la peticion en un objeto de tipo json EntidadPeticion peticion = servicioSeguridad.ToEntidadPeticion(peticionSegura); var insercion = Task.Run(async() => await servicioInsertaInformacion.InsertaPeticion(peticion)); //Lanzamos la peticion para que inserte los datos de forma asincrona if (insercion.Result) { exchange.Respond(CoAP.StatusCode.Changed); } else { log.Error("ERR RECURSOPETICION (DoPost) - No se ha podido insertar la información en la base de datos."); exchange.Respond(CoAP.StatusCode.BadRequest); } } else { log.Error("ERR RECURSOPETICION (DoPost) - La petición está vacía."); } }
protected override void DoGet(CoapExchange exchange) { String content = $"Hello from "; content += Encoding.UTF8.GetString(exchange.Request.TlsContext.AuthenticationKey[CoseKeyKeys.KeyIdentifier].GetByteString()); exchange.Respond(content); }
protected override void DoPost(CoapExchange exchange) { String old = _content; _content = exchange.Request.PayloadString; exchange.Respond(StatusCode.Changed, old); Changed(); }
protected override void DoPost(CoapExchange exchange) { StringBuilder sb = new StringBuilder(); sb.AppendFormat("POST to /location_query w/ options {0}", exchange.Request.UriQueries); exchange.Respond(StatusCode.Changed, sb.ToString(), MediaType.TextPlain); }
protected override void DoGet(CoapExchange exchange) { #if COAPALL || COAP03 || COAP08 || COAP12 || COAP13 || COAP18 || RFC7252 exchange.Respond("Ni Hao from CoAP.NET " + _server._config.Spec.Name); #else exchange.Respond("Ni Hao from CoAP.NET " + Spec.Name); #endif }
protected override void DoGet(CoapExchange exchange) { if (_mode == Mode.Separate) { exchange.Accept(); } _currentResponseText = "hello get " + _status; exchange.Respond(_currentResponseText); }
protected override void DoGet(CoapExchange exchange) { Console.WriteLine("GET on {0} with ", Uri); Console.WriteLine(DateTime.Now.ToLongDateString()); Console.WriteLine(Utils.ToString(exchange.Request)); Request request = exchange.Request; Response response; switch (Name) { case "1": { response = new Response(StatusCode.Content) { PayloadString = "Hello World!", ContentFormat = 0 }; break; } case "2": { response = new Response(StatusCode.Content) { PayloadString = "Hello World!", ContentFormat = MediaType.TextPlain }; response.AddETag(new byte[] { 0x2b }); break; } case "3": { response = new Response(StatusCode.Content) { PayloadString = "Hello World!", ContentFormat = MediaType.TextPlain, MaxAge = 5 }; break; } case "coap": { response = new Response(StatusCode.Content) { PayloadString = "Hello World!" }; break; } default: response = new Response(StatusCode.BadRequest); break; } Console.WriteLine(Utils.ToString(response)); exchange.Respond(response); }
protected override void DoPut(CoapExchange exchange) { string payload = exchange.Request.PayloadString; string[] payloads = payload.Split(':'); _content = payloads[0]; string sequencNum = payloads[1]; exchange.Respond(StatusCode.Changed); }
protected override void DoGet(CoapExchange exchange) { exchange.Accept(); Thread.Sleep(1000); Request req = exchange.Request; StringBuilder sb = new StringBuilder("Deferred Response"); exchange.Respond(StatusCode.Content, sb.ToString()); }
protected override void DoPost(CoapExchange exchange) { string payload = exchange.Request.PayloadString; dynamic product = JObject.Parse(payload); string name = product.name; double price = product.price; database.AddProduct(name, price); exchange.Respond("Added!"); }
protected override void DoGet(CoapExchange exchange) { if (fActive) { exchange.Respond(StatusCode.Content, content); } else { exchange.Respond(StatusCode.NotFound); } }
protected override void DoGet(CoapExchange exchange) { Request req = exchange.Request; StringBuilder sb = new StringBuilder(); sb.Append("Query resource - parameters are"); sb.Append(req.UriQueries); exchange.Respond(StatusCode.Content, sb.ToString()); }
protected override void DoGet(CoapExchange exchange) { Request request = exchange.Request; if (request.IsMulticast) { return; } exchange.Respond(StatusCode.Content, _content); }
protected override void DoGet(CoapExchange exchange) { Request r = exchange.Request; StringBuilder sb = new StringBuilder(); sb.Append("Long path resorce "); sb.Append(r.UriPaths); exchange.Respond(StatusCode.Content, sb.ToString()); }
protected override void DoGet(CoapExchange exchange) { String c = this.Uri; String querys = exchange.Request.UriQuery; if (querys != "") { c += "?" + querys; } exchange.Respond(c); }
protected override void DoGet(CoapExchange exchange) { if (_content != null) { exchange.Respond(_content); } else { String subtree = LinkFormat.Serialize(this, null); exchange.Respond(StatusCode.Content, subtree, MediaType.ApplicationLinkFormat); } }