Ejemplo n.º 1
0
        public WinHttpSession(
            Uri responseUri,
            SafeWinHttpHandle hConnect,
            SafeWinHttpHandle hRequest,
            Dictionary <string, List <string> >?headers,
            Dictionary <string, string>?cookies,
            byte[]?postData = null)
        {
            this.responseUri = responseUri;
            this.hConnect    = hConnect;
            this.hRequest    = hRequest;
            this.callback    = new(WinHttpCallback);
            IntPtr oldCallback = WinHttpSetStatusCallback(
                hRequest,
                this.callback,
                WINHTTP_CALLBACK_FLAG_REDIRECT,
                IntPtr.Zero);

            if (oldCallback == new IntPtr(WINHTTP_INVALID_STATUS_CALLBACK))
            {
                int lastError = Marshal.GetLastWin32Error();
                if (lastError != ERROR_INVALID_HANDLE) // Ignore error if handle was already closed.
                {
                    throw new IOException(nameof(WinHttpSetStatusCallback));
                }
            }
            this.headers = headers;
            this.cookies = cookies;
            if (postData != null && postData.Length > 0)
            {
                this.postData = Marshal.AllocHGlobal(postData.Length);
                Marshal.Copy(postData, 0, this.postData.Value, postData.Length);
                this.postDataSize = postData.Length;
            }
            this.responseStream = new WinHttpResponseStream(this.hRequest);
        }
Ejemplo n.º 2
0
 public static extern IntPtr WinHttpSetStatusCallback(
     SafeWinHttpHandle handle,
     WINHTTP_STATUS_CALLBACK callback,
     uint notificationFlags,
     IntPtr reserved);
Ejemplo n.º 3
0
 public static extern IntPtr WinHttpSetStatusCallback(
     SafeWinHttpHandle handle,
     WINHTTP_STATUS_CALLBACK callback,
     uint notificationFlags,
     IntPtr reserved);