public async Task <HttpResponseMessage> SendPutRequest(string url, string jsonBody)
        {
            if (TryGetUri(url, out uri))
            {
                try
                {
                    IHttpContent        httpContent = new HttpJsonContent(JsonValue.Parse(jsonBody));
                    HttpResponseMessage response    = await httpClient.PutAsync(uri,
                                                                                httpContent).AsTask(cts.Token);

                    return(response);
                }
                catch (OperationCanceledException e)
                { }
                catch (Exception ex)
                {
                    if (errorCounter < 2)
                    {
                        errorCounter++;
                        await SendPutRequest(url, jsonBody);
                    }
                }
            }
            return(null);
        }
Esempio n. 2
0
            public async Task <HttpResponseMessage> PutAsync(Uri uri, JObject body)
            {
                IHttpContent        jsonContent = new HttpJsonContent(body);
                HttpResponseMessage response    = null;
                string meta = $"PUT {uri}";

                try {
                    Debug.WriteLine($"Requesting: {meta}");
                    Debug.WriteLine($"with body: {JsonConvert.SerializeObject(body, Formatting.Indented)}");
                    response = await httpClient.PutAsync(uri, jsonContent);
                } catch (Exception e) {
                    throw new MatrixException.NetworkError(meta, e);
                }
                return(response);
            }