ACMESharp.AcmeClient.RequestHttpPost C# (CSharp) Method

RequestHttpPost() private method

Submits an ACME protocol request via an HTTP POST with the necessary semantics and protocol details. The result is a simplified and canonicalized response object capturing the error state, HTTP response headers and content of the response body.
private RequestHttpPost ( Uri uri, object message ) : AcmeHttpResponse
uri System.Uri
message object
return AcmeHttpResponse
        private AcmeHttpResponse RequestHttpPost(Uri uri, object message)
        {
            var acmeSigned = ComputeAcmeSigned(message, Signer);
            var acmeBytes = Encoding.ASCII.GetBytes(acmeSigned);

            var requ = (HttpWebRequest)WebRequest.Create(uri);
            if (Proxy != null)
                requ.Proxy = Proxy;
            requ.Method = AcmeProtocol.HTTP_METHOD_POST;
            requ.ContentType = AcmeProtocol.HTTP_CONTENT_TYPE_JSON;
            requ.ContentLength = acmeBytes.Length;
            requ.UserAgent = this.UserAgent;
            try
            {
                if (BeforeGetResponseAction != null)
                    BeforeGetResponseAction(requ);

                using (var s = requ.GetRequestStream())
                {
                    s.Write(acmeBytes, 0, acmeBytes.Length);
                }

                using (var resp = (HttpWebResponse)requ.GetResponse())
                {
                    ExtractNonce(resp);
                    var acmeResp = new AcmeHttpResponse(resp);
                    LastResponse = acmeResp;
                    return acmeResp;
                }
            }
            catch (WebException ex) when (ex.Response != null)
            {
                using (var resp = (HttpWebResponse)ex.Response)
                {
                    var acmeResp = new AcmeHttpResponse(resp)
                    {
                        IsError = true,
                        Error = ex,
                    };
                    LastResponse = acmeResp;

                    if (ProblemDetailResponse.CONTENT_TYPE == resp.ContentType
                            && !string.IsNullOrEmpty(acmeResp.ContentAsString))
                    {
                        acmeResp.ProblemDetail = JsonConvert.DeserializeObject<ProblemDetailResponse>(
                                acmeResp.ContentAsString);
                        acmeResp.ProblemDetail.OrignalContent = acmeResp.ContentAsString;
                    }

                    return acmeResp;
                }
            }
        }