NewGet() публичный статический Метод

Construct a GET request.
public static NewGet ( ) : Request
Результат Request
Пример #1
0
        public void TestServer()
        {
            // We do not test for block 0 because the client is currently unable to
            // know if the user attempts to just retrieve block 0 or if he wants to
            // do early block negotiation with a specific size but actually wants to
            // retrieve all blocks.

            Int32[]  blockOrder   = { 2, 1, 3 };
            String[] expectations =
            {
                RESPONSE_PAYLOAD.Substring(32 /* until the end */),
                RESPONSE_PAYLOAD.Substring(16, 16),
                null // block is out of bounds
            };

            for (Int32 i = 0; i < blockOrder.Length; i++)
            {
                Int32 num = blockOrder[i];
                Console.WriteLine("Request block number " + num);
                Int32   szx     = BlockOption.EncodeSZX(16);
                Request request = Request.NewGet();
                request.URI = new Uri("coap://localhost:" + _serverPort + "/" + TARGET);
                request.SetBlock2(szx, false, num);
                request.Send();
                Response response = request.WaitForResponse(1000);
                Assert.IsNotNull(response);
                Assert.AreEqual(expectations[i], response.PayloadString);
                Assert.IsTrue(response.HasOption(OptionType.Block2));
                Assert.AreEqual(num, response.Block2.NUM);
                Assert.AreEqual(szx, response.Block2.SZX);
            }
        }
Пример #2
0
        private void ExecuteGETRequest()
        {
            String payload = "nothing";

            try
            {
                Request request = Request.NewGet();
                request.Destination = new IPEndPoint(IPAddress.Loopback, _serverPort);
                request.Send(_clientEndpoint);

                // receive response and check
                Response response = request.WaitForResponse(1000);

                Assert.IsNotNull(response);
                payload = response.PayloadString;
                if (respond_short)
                {
                    Assert.AreEqual(SHORT_GET_RESPONSE, payload);
                }
                else
                {
                    Assert.AreEqual(LONG_GET_RESPONSE, payload);
                }
            }
            finally
            {
                Thread.Sleep(100); // Quickly wait until last ACKs arrive
            }
        }
Пример #3
0
        /// <summary>
        /// Discovers remote resources.
        /// </summary>
        /// <param name="query">the query to filter resources</param>
        /// <returns>the descoverd <see cref="WebLink"/> representing remote resources, or null if no response</returns>
        public IEnumerable <WebLink> Discover(String query)
        {
            Request discover = Prepare(Request.NewGet());

            discover.ClearUriPath().ClearUriQuery().UriPath = CoapConstants.DefaultWellKnownURI;
            if (!String.IsNullOrEmpty(query))
            {
                discover.UriQuery = query;
            }
            Response links = discover.Send().WaitForResponse(_timeout);

            if (links == null)
            {
                // if no response, return null (e.g., timeout)
                return(null);
            }
            else if (links.ContentFormat != MediaType.ApplicationLinkFormat)
            {
                return(EmptyLinks);
            }
            else
            {
                return(LinkFormat.Parse(links.PayloadString));
            }
        }
Пример #4
0
        private void SendRequestAndExpect(String expected)
        {
            Thread.Sleep(100);
            Request request = Request.NewGet();

            request.SetUri("localhost:" + _serverPort + "/ress");
            String response = request.Send().WaitForResponse(1000).PayloadString;

            Assert.AreEqual(expected, response);
        }
Пример #5
0
        public void TestDiscoveryFiltering()
        {
            String expected = "</sensors/light>;if=\"sensor\";rt=\"light-lux\"";

            Request request = Request.NewGet();

            request.SetUri("/.well-known/core?rt=light-lux");

            DiscoveryResource discovery  = new DiscoveryResource(_root);
            String            serialized = LinkFormat.Serialize(_root, request.UriQueries);

            Assert.AreEqual(expected, serialized);
        }
Пример #6
0
        private void TestSimpleNONGet(Uri uri)
        {
            Console.WriteLine("Test simple NON GET to " + uri);

            Request request = Request.NewGet();

            request.URI  = uri;
            request.Type = MessageType.NON;
            Response response = request.Send(_clientEndpoint).WaitForResponse(1000);

            Console.WriteLine("Client received response " + response.PayloadString + " with msg type " + response.Type);
            Assert.AreEqual(_currentResponseText, response.PayloadString);
            Assert.AreEqual(MessageType.NON, response.Type);

            _serverSurveillant.WaitUntilDeduplicatorShouldBeEmpty();
            _serverSurveillant.AssertMapsEmpty();
            _clientSurveillant.AssertMapsEmpty();
        }
Пример #7
0
        public void ProactiveCancel()
        {
            Request cancel = Request.NewGet();

            // copy options, but set Observe to cancel
            cancel.SetOptions(_request.GetOptions());
            cancel.MarkObserveCancel();
            // use same Token
            cancel.Token       = _request.Token;
            cancel.Destination = _request.Destination;

            // dispatch final response to the same message observers
            cancel.CopyEventHandler(_request);

            cancel.Send(_endpoint);
            // cancel old ongoing request
            _request.IsCancelled = true;
            _canceled            = true;
        }
Пример #8
0
        public void TestNameChange()
        {
            String baseUri = "coap://localhost:" + _serverPort + "/" + RES_A + "/" + RES_AA + "/";

            // First check that we reach the resource
            String resp1 = Request.NewGet().SetUri(baseUri + NAME_1).Send().WaitForResponse(100).PayloadString;

            Assert.AreEqual(PAYLOAD, resp1);

            // Check that the child of 'first' is also reachable
            String resp2 = Request.NewGet().SetUri(baseUri + NAME_1 + "/" + CHILD).Send().WaitForResponse(100).PayloadString;

            Assert.AreEqual(CHILD_PAYLOAD, resp2);

            // change the name to 'second'
            _resource.Name = NAME_2;

            // Check that the resource reacts
            String resp3 = Request.NewGet().SetUri(baseUri + NAME_2).Send().WaitForResponse(100).PayloadString;

            Assert.AreEqual(PAYLOAD, resp3);

            // Check that the child of (now) 'second' is also reachable
            String resp4 = Request.NewGet().SetUri(baseUri + NAME_2 + "/" + CHILD).Send().WaitForResponse(100).PayloadString;

            Assert.AreEqual(CHILD_PAYLOAD, resp4);

            // Check that the resource is not found at the old URI
            StatusCode code1 = Request.NewGet().SetUri(baseUri + NAME_1).Send().WaitForResponse(100).StatusCode;

            Assert.AreEqual(StatusCode.NotFound, code1);

            // Check that the child of (now) 'second' is not reachable under 'first'
            StatusCode code2 = Request.NewGet().SetUri(baseUri + NAME_1 + "/" + CHILD).Send().WaitForResponse(100).StatusCode;

            Assert.AreEqual(StatusCode.NotFound, code2);
        }
Пример #9
0
 public CoapObserveRelation ObserveAsync(Int32 accept, Action <Response> notify = null, Action <FailReason> error = null)
 {
     return(ObserveAsync(Accept(Request.NewGet().MarkObserve(), accept), notify, error));
 }
Пример #10
0
 public CoapObserveRelation Observe(Action <Response> notify = null, Action <FailReason> error = null)
 {
     return(Observe(Request.NewGet().MarkObserve(), notify, error));
 }
Пример #11
0
 public Response Validate(params Byte[][] etags)
 {
     return(Send(ETags(Request.NewGet(), etags)));
 }
Пример #12
0
 /// <summary>
 /// Sends a GET request with the specified Accept option asynchronizely.
 /// </summary>
 /// <param name="accept">the Accept option</param>
 /// <param name="done">the callback when a response arrives</param>
 /// <param name="fail">the callback when an error occurs</param>
 public void GetAsync(Int32 accept, Action <Response> done = null, Action <FailReason> fail = null)
 {
     SendAsync(Accept(Request.NewGet(), accept), done, fail);
 }
Пример #13
0
 /// <summary>
 /// Sends a GET request with the specified Accept option and blocks
 /// until the response is available.
 /// </summary>
 /// <param name="accept">the Accept option</param>
 /// <returns>the CoAP response</returns>
 public Response Get(Int32 accept)
 {
     return(Send(Accept(Request.NewGet(), accept)));
 }
Пример #14
0
 /// <summary>
 /// Sends a GET request and blocks until the response is available.
 /// </summary>
 /// <returns>the CoAP response</returns>
 public Response Get()
 {
     return(Send(Request.NewGet()));
 }