OCISDK/OCISDK/Common/RestClientAsync.cs
/// <summary>
/// Post a request object to the endpoint represented by the web target and get the response.
/// </summary>
/// <param name="targetUri"></param>
/// <param name="requestBody"></param>
/// <param name="httpRequestHeaderParam"></param>
/// <param name="bodyJsonSerialize"></param>
/// <returns></returns>
Post a request object to the endpoint represented by the web target and get the response.
Post a request object to the endpoint represented by the web target and get the response .
public async Task<WebResponse> Post(Uri targetUri, object requestBody, HttpRequestHeaderParam httpRequestHeaderParam, bool bodyJsonSerialize)
        {
            var request = (HttpWebRequest)WebRequest.Create(targetUri);
            if (httpRequestHeaderParam != null)
            {
                request = httpRequestHeaderParam.SetHeader(request);
            }
            byte[] arr = CreateBodyBytes(request, requestBody, bodyJsonSerialize);
            request.ContentLength = arr.Length;
            request.Headers["x-content-sha256"] = Convert.ToBase64String(SHA256.Create().ComputeHash(arr));
            request.Accept = "*/*";
            request.ContentType = "application/json";
            request.KeepAlive = true;
            if (WebProxy != null)
            {
                request.Proxy = WebProxy;
            }
            request.Method = HttpMethod.Post.Method;
            if (Signer != null)
            {
                Signer.SignRequest(request);
            }
            using (Stream dataStream = request.GetRequestStream())
            {
                dataStream.Write(arr, 0, arr.Length);
            }
            var res = await WebRequestPolicy.GetPoliciesAsync(Option).ExecuteAndCaptureAsync(() => request.GetResponseAsync());
            if (res.Outcome == OutcomeType.Failure && (res.FinalException is WebException))
            {
                throw res.FinalException;
            }
            return res.Result;
        }
public async Task < WebResponse > Post ( Uri targetUri , object requestBody , HttpRequestHeaderParam httpRequestHeaderParam , bool bodyJsonSerialize ) { var request = ( HttpWebRequest ) WebRequest . Create ( targetUri ) ; if ( httpRequestHeaderParam != null ) { request = httpRequestHeaderParam . SetHeader ( request ) ; } byte [ ] arr = CreateBodyBytes ( request , requestBody , bodyJsonSerialize ) ; request . ContentLength = arr . Length ; request . Headers [ " " ] = Convert . ToBase64String ( SHA256 . Create ( ) . ComputeHash ( arr ) ) ; request . Accept = " " ; request . ContentType = " " ; request . KeepAlive = true ; if ( WebProxy != null ) { request . Proxy = WebProxy ; } request . Method = HttpMethod . Post . Method ; if ( Signer != null ) { Signer . SignRequest ( request ) ; } using ( Stream dataStream = request . GetRequestStream ( ) ) { dataStream . Write ( arr , 0 , arr . Length ) ; } var res = await WebRequestPolicy . GetPoliciesAsync ( Option ) . ExecuteAndCaptureAsync ( ( ) => request . GetResponseAsync ( ) ) ; if ( res . Outcome == OutcomeType . Failure && ( res . FinalException is WebException ) ) { throw res . FinalException ; } return res . Result ; }
Post a request object to the endpoint represented by the web target and get the response.
Post a request object to the endpoint represented by the web target and get the response .
None
targetUri
Uri
None
requestBody
object
None
httpRequestHeaderParam
HttpRequestHeaderParam
None
bodyJsonSerialize
bool
None