OCISDK/OCISDK/Common/RestClient.cs
/// <summary>
/// Execute a delete on a resource and get the response.
/// </summary>
/// <param name="targetUri"></param>
/// <param name="httpRequestHeaderParam"></param>
/// <param name="requestBody"></param>
/// <returns></returns>
Execute a delete on a resource and get the response.
Execute a delete on a resource and get the response .
public HttpWebResponse Delete(Uri targetUri, HttpRequestHeaderParam httpRequestHeaderParam, object requestBody)
        {
            var request = (HttpWebRequest)WebRequest.Create(targetUri);
            request.Method = HttpMethod.Delete.Method;
            request.ReadWriteTimeout = Option.TimeoutSeconds;
            if (httpRequestHeaderParam != null)
            {
                request = httpRequestHeaderParam.SetHeader(request);
            }
            if (requestBody != null)
            {
                var body = JsonSerializer.Serialize(requestBody);
                var bytes = Encoding.UTF8.GetBytes(body);
                request.Headers["x-content-sha256"] = Convert.ToBase64String(SHA256.Create().ComputeHash(bytes));
                request.ContentLength = bytes.Length;
                using (var stream = request.GetRequestStream())
                {
                    stream.Write(bytes, 0, bytes.Length);
                }
            }
            if (Signer != null)
            {
                Signer.SignRequest(request);
            }
            var res = WebRequestPolicy.GetPolicies(Option).ExecuteAndCapture(() => (HttpWebResponse)request.GetResponse());
            if (res.Outcome == OutcomeType.Failure && (res.FinalException is WebException))
            {
                throw res.FinalException;
            }
            return res.Result;
        }
public HttpWebResponse Delete ( Uri targetUri , HttpRequestHeaderParam httpRequestHeaderParam , object requestBody ) { var request = ( HttpWebRequest ) WebRequest . Create ( targetUri ) ; request . Method = HttpMethod . Delete . Method ; request . ReadWriteTimeout = Option . TimeoutSeconds ; if ( httpRequestHeaderParam != null ) { request = httpRequestHeaderParam . SetHeader ( request ) ; } if ( requestBody != null ) { var body = JsonSerializer . Serialize ( requestBody ) ; var bytes = Encoding . UTF8 . GetBytes ( body ) ; request . Headers [ " " ] = Convert . ToBase64String ( SHA256 . Create ( ) . ComputeHash ( bytes ) ) ; request . ContentLength = bytes . Length ; using ( var stream = request . GetRequestStream ( ) ) { stream . Write ( bytes , 0 , bytes . Length ) ; } } if ( Signer != null ) { Signer . SignRequest ( request ) ; } var res = WebRequestPolicy . GetPolicies ( Option ) . ExecuteAndCapture ( ( ) => ( HttpWebResponse ) request . GetResponse ( ) ) ; if ( res . Outcome == OutcomeType . Failure && ( res . FinalException is WebException ) ) { throw res . FinalException ; } return res . Result ; }
Execute a delete on a resource and get the response.
Execute a delete on a resource and get the response .
None
targetUri
Uri
None
httpRequestHeaderParam
HttpRequestHeaderParam
None
requestBody
object
None