void InitializeNativeRequest ()
{
native = NativeMethods.deployment_create_http_request (System.Windows.Deployment.Current.native, HttpRequestOptions.CustomHeaders);
if (native == IntPtr.Zero)
throw new NotSupportedException ("Failed to create unmanaged HttpRequest object");
Events.AddHandler (native, EventIds.HttpRequest_StartedEvent, started);
Events.AddHandler (native, EventIds.HttpRequest_WriteEvent, available);
Events.AddHandler (native, EventIds.HttpRequest_StoppedEvent, finished);
NativeMethods.http_request_open (native, Method, RequestUri.AbsoluteUri, DownloaderAccessPolicy.NoPolicy);
long request_length = 0;
byte[] body = null;
if (request != null) {
request.Close ();
body = request.GetData ();
request_length = body.Length;
}
if (request_length > 1) {
// this header cannot be set directly inside the collection (hence the helper)
Headers.SetHeader ("content-length", request_length.ToString ());
}
foreach (string header in Headers.AllKeys)
NativeMethods.http_request_set_header (native, header, Headers [header], false);
if (request_length > 1) {
NativeMethods.http_request_set_body (native, body, body.Length);
}
NativeMethods.http_request_send (native);
}
}