/// <summary> /// Posts the data to the specified URI. /// </summary> /// <typeparam name="T">The type of expected result</typeparam> /// <param name="client">The client.</param> /// <param name="context">The context.</param> /// <param name="location">The URI.</param> /// <param name="entity">The payload.</param> /// <param name="ensureSuccessStatusCode">if set to <c>true</c>, throw exception if the request failed.</param> /// <returns> /// The response from ACME server. /// </returns> /// <exception cref="Exception"> /// If the HTTP request failed and <paramref name="ensureSuccessStatusCode"/> is <c>true</c>. /// </exception> internal static async Task <AcmeHttpResponse <T> > Post <T>(this IAcmeHttpClient client, IAcmeContext context, Uri location, object entity, bool ensureSuccessStatusCode) { var payload = await context.Sign(entity, location); var response = await client.Post <T>(location, payload); var retryCount = context.BadNonceRetryCount; while (response.Error?.Status == System.Net.HttpStatusCode.BadRequest && response.Error.Type?.CompareTo("urn:ietf:params:acme:error:badNonce") == 0 && retryCount-- > 0) { payload = await context.Sign(entity, location); response = await client.Post <T>(location, payload); } if (ensureSuccessStatusCode && response.Error != null) { throw new AcmeRequestException( string.Format(Strings.ErrorFetchResource, location), response.Error); } return(response); }
/// <summary> /// Posts the data to the specified URI. /// </summary> /// <typeparam name="T">The type of expected result</typeparam> /// <param name="client">The client.</param> /// <param name="uri">The URI.</param> /// <param name="payload">The payload.</param> /// <param name="ensureSuccessStatusCode">if set to <c>true</c>, throw exception if the request failed.</param> /// <returns> /// The response from ACME server. /// </returns> /// <exception cref="Exception"> /// If the HTTP request failed and <paramref name="ensureSuccessStatusCode"/> is <c>true</c>. /// </exception> internal static async Task<AcmeHttpResponse<T>> Post<T>(this IAcmeHttpClient client, Uri uri, object payload, bool ensureSuccessStatusCode) { var resp = await client.Post<T>(uri, payload); if (ensureSuccessStatusCode && resp.Error != null) { throw new Exception(resp.Error.Detail); } return resp; }
/// <summary> /// Posts the data to the specified URI. /// </summary> /// <typeparam name="T">The type of expected result</typeparam> /// <param name="client">The client.</param> /// <param name="uri">The URI.</param> /// <param name="payload">The payload.</param> /// <param name="ensureSuccessStatusCode">if set to <c>true</c>, throw exception if the request failed.</param> /// <returns> /// The response from ACME server. /// </returns> /// <exception cref="Exception"> /// If the HTTP request failed and <paramref name="ensureSuccessStatusCode"/> is <c>true</c>. /// </exception> internal static async Task <AcmeHttpResponse <T> > Post <T>(this IAcmeHttpClient client, Uri uri, object payload, bool ensureSuccessStatusCode) { var resp = await client.Post <T>(uri, payload); if (ensureSuccessStatusCode && resp.Error != null) { throw new AcmeRequestException( string.Format(Strings.ErrorFetchResource, uri), resp.Error); } return(resp); }