/// <summary> /// Makes a HTTP POST request with the given request object. This is /// performed asynchronously, with the callback block run on a background /// thread. /// </summary> /// /// <param name="request">The POST HTTP request.</param> /// <param name="callback">The callback which will provide the response from the server. /// The callback will be made on a background thread.</param> public void SendRequest(HttpPostRequest request, Action <HttpPostRequest, HttpResponse> callback) { ReleaseAssert.IsTrue(request != null, "The HTTP POST request must not be null when sending a request."); ReleaseAssert.IsTrue(callback != null, "The callback must not be null when sending a request."); var headers = new Dictionary <string, string>(request.Headers); if (request.ContentType != null) { headers.Add("Content-Type", request.ContentType); } SendRequest(request.Url, headers, request.Body, (HttpResponse response) => { callback(request, response); }); }
/// <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); // }); // } }); }