protected override async Task <HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) { string url = request.RequestUri.ToString(); var okRequest = new Request.Builder(); okRequest.Url(url); RequestBody requestBody = null; foreach (var header in request.Headers) { okRequest.AddHeader(header.Key, string.Join(" ", header.Value)); } if (request.Content != null) { /*foreach (var header in request.Content.Headers) * { * okRequest.AddHeader(header.Key, string.Join(" ", header.Value)); * }*/ var contentType = MediaType.Parse(request.Content.Headers.ContentType?.ToString() ?? "application/octat-stream"); using (var ms = new System.IO.MemoryStream()) { var s = await request.Content.ReadAsStreamAsync().ConfigureAwait(false); await s.CopyToAsync(ms).ConfigureAwait(false); requestBody = RequestBody.Create(contentType, ms.ToArray()); } } okRequest.Method(request.Method.ToString(), requestBody); string cookie = GetCookie(url); if (cookie != null) { okRequest.AddHeader("Cookie", cookie); } var call = Client.NewCall(okRequest.Build()); var callBack = new OkHttpCallBack(); call.Enqueue(callBack); var okResponse = await callBack.taskSource.Task.ConfigureAwait(false); var response = new HttpResponseMessage(); response.StatusCode = (System.Net.HttpStatusCode)okResponse.Code(); List <KeyValuePair <string, string> > contentHeaders = new List <KeyValuePair <string, string> >(); var rhs = response.Headers; var hs = okResponse.Headers(); int total = hs.Size(); for (int i = 0; i < total; i++) { var name = hs.Name(i); var value = hs.Value(i); if (name.EqualsIgnoreCase("Set-Cookie") || name.EqualsIgnoreCase("Set-Cookie2")) { Android.Webkit.CookieManager.Instance.SetCookie(url, value); PrefCookieHandler.Default.SetCookie(url, value); cookieCache.Clear(); } //System.Diagnostics.Debug.Write($"Header: {name} = {value}"); if (!rhs.TryAddWithoutValidation(name, value)) { contentHeaders.Add(new KeyValuePair <string, string>(name, value)); } } var st = okResponse.Body().ByteStream(); response.Content = new StreamContent(st); foreach (var ch in contentHeaders) { response.Content.Headers.TryAddWithoutValidation(ch.Key, ch.Value); } //HttpResponseMessage return(response); }