/// <summary> /// Initialises the HTTP POST request with the given description. /// </summary> /// /// <param name="desc">The description of the HTTP POST request.</param> public HttpPostRequest(HttpPostRequestDesc desc) { ReleaseAssert.IsTrue(desc != null, "The description of a HTTP POST request must 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 of a HTTP POST request must not be null."); ReleaseAssert.IsTrue(desc.Body != null, "The body of a HTTP POST request must not be null."); Url = desc.Url; Body = desc.Body; Headers = desc.Headers; ContentType = desc.ContentType; }
/// <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); // }); // } }); }