private void SendWebRequestAsync <TResponse>(string httpMethod, object request, AsyncState <TResponse> state, HttpWebRequest client) { client.Accept = ContentType; if (this.EmulateHttpViaPost) { client.Method = "POST"; client.Headers[HttpHeaders.XHttpMethodOverride] = httpMethod; } else { client.Method = httpMethod; } PclExportClient.Instance.AddHeader(client, Headers); //EmulateHttpViaPost is also forced for SL5 clients sending non GET/POST requests PclExport.Instance.Config(client, userAgent: UserAgent); if (this.authInfo != null && !string.IsNullOrEmpty(this.UserName)) { client.AddAuthInfo(this.UserName, this.Password, authInfo); } else if (this.BearerToken != null) { client.Headers[HttpHeaders.Authorization] = "Bearer " + this.BearerToken; } else if (this.Credentials != null) { client.Credentials = this.Credentials; } else if (this.AlwaysSendBasicAuthHeader) { client.AddBasicAuth(this.UserName, this.Password); } ApplyWebRequestFilters(client); try { if (client.Method.HasRequestBody()) { client.ContentType = ContentType; client.BeginGetRequestStream(RequestCallback <TResponse>, state); } else { state.WebRequest.BeginGetResponse(ResponseCallback <TResponse>, state); } } catch (Exception ex) { // BeginGetRequestStream can throw if request was aborted HandleResponseError(ex, state); } }