예제 #1
0
        /// <summary>
        /// Initializes a new HTTP GET request using the given description.
        /// </summary>
        ///
        /// <param name="desc">The description of the HTTP GET request.</param>
        public HttpGetRequest(HttpGetRequestDesc desc)
        {
            ReleaseAssert.IsTrue(desc != null, "A HTTP GET request description should not be null.");
            ReleaseAssert.IsTrue(desc.Url != null, "The URL in a HTTP GET request must not be null.");
            ReleaseAssert.IsTrue(desc.Headers != null, "The headers in a HTTP GET request must not be null.");

            Url     = desc.Url;
            Headers = desc.Headers;
        }
예제 #2
0
        /// <summary>
        /// Performs a server request with the given request parameters. This is
        /// performed asynchronously.
        /// </summary>
        ///
        /// <param name="request">The request that should be performed, which must adhere
        /// to the immediate request protocol.</param>
        /// <param name="callback">The callback containing the response. The callback
        /// will be on a background thread.</param>
        public void SendImmediateRequest(IImmediateServerRequest request, Action <IImmediateServerRequest, ServerResponse> callback)
        {
            m_taskScheduler.ScheduleBackgroundTask(() =>
            {
                if (request.HttpRequestMethod == HttpRequestMethod.Post)
                {
                    var bodyString = MiniJSON.Json.Serialize(request.SerialiseBody());
                    ReleaseAssert.IsTrue(bodyString != null, "Invalid body.");
                    var bodyData = Encoding.UTF8.GetBytes(bodyString);

                    var httpRequestDesc         = new HttpPostRequestDesc(request.Url, bodyData);
                    httpRequestDesc.Headers     = request.SerialiseHeaders();
                    httpRequestDesc.ContentType = "application/json";

                    var httpRequest = new HttpPostRequest(httpRequestDesc);
                    m_httpSystem.SendRequest(httpRequest, (HttpPostRequest receivedHttpRequest, HttpResponse httpResponse) =>
                    {
                        ReleaseAssert.IsTrue(httpRequest == receivedHttpRequest, "Received response for wrong request.");

                        var serverResponse = new ServerResponse(httpResponse);
                        callback(request, serverResponse);
                    });
                }
                else
                {
                    var httpRequestDesc     = new HttpGetRequestDesc(request.Url);
                    httpRequestDesc.Headers = request.SerialiseHeaders();

                    var httpRequest = new HttpGetRequest(httpRequestDesc);
                    m_httpSystem.SendRequest(httpRequest, (HttpGetRequest receivedHttpRequest, HttpResponse httpResponse) =>
                    {
                        ReleaseAssert.IsTrue(httpRequest == receivedHttpRequest, "Received response for wrong request.");

                        var serverResponse = new ServerResponse(httpResponse);
                        callback(request, serverResponse);
                    });
                }
            });
        }