public override IAsyncResult BeginGetResponse (AsyncCallback callback, object state)
{
// under SL the callback MUST call the EndGetResponse, so having no callback is BAD
// this also means that faking a synch op using EndGetReponse(BeginGetReponse(null,null)) does NOT work
if (callback == null)
throw new NotSupportedException ();
// copy Method, Cookies and Headers to System.dll's HttpWebRequest
try {
if (Credentials != null) {
NetworkCredential nc = Credentials.GetCredential (RequestUri, String.Empty);
set_credentials.Invoke (request,
ClientReflectionHelper.BuildCredentials (nc.UserName, nc.Password, nc.Domain));
}
if ((CookieContainer != null) && (CookieContainer.Count > 0)) {
string cookieHeader = CookieContainer.GetCookieHeader (RequestUri);
if (!String.IsNullOrEmpty (cookieHeader))
ClientReflectionHelper.SetHeader (headers, "Cookie", cookieHeader);
}
if (ContentType != null) {
set_content_type.Invoke (request, new object [] { ContentType } );
}
if (Headers.Count > 0) {
string [] keys = Headers.AllKeys;
foreach (string key in keys) {
// we cannot set "Content-Type" using the headers
if (String.Compare (key, "content-type", StringComparison.OrdinalIgnoreCase) != 0)
ClientReflectionHelper.SetHeader (headers, key, Headers [key]);
}
}
IAsyncResult async_result = new HttpWebAsyncResult (callback, state);
asyncResult = (IAsyncResult) begin_get_response.Invoke (request,
new object [2] { new AsyncCallback (EndCallback), async_result });
return async_result;
}
catch (TargetInvocationException tie) {
throw tie.InnerException;
}
}