public static partial bool WinHttpQueryHeaders( SafeWinHttpHandle requestHandle, uint infoLevel, string name, ref uint number, ref uint bufferLength, IntPtr index);
public static extern bool WinHttpAddRequestHeaders( SafeWinHttpHandle requestHandle, #pragma warning disable CA1838 // Uses pooled StringBuilder [In] StringBuilder headers, #pragma warning restore CA1838 uint headersLength, uint modifiers);
public static partial bool WinHttpSetCredentials( SafeWinHttpHandle requestHandle, uint authTargets, uint authScheme, string? userName, string? password, IntPtr reserved);
public static extern bool WinHttpQueryHeaders( SafeWinHttpHandle requestHandle, uint infoLevel, string name, [Out] StringBuilder buffer, ref uint bufferLength, ref uint index);
public static extern bool WinHttpSendRequest( SafeWinHttpHandle requestHandle, [In] StringBuilder headers, uint headersLength, IntPtr optional, uint optionalLength, uint totalLength, IntPtr context);
public static void DisposeAndClearHandle(ref SafeWinHttpHandle handle) { if (handle != null) { handle.Dispose(); handle = null; } }
public static extern SafeWinHttpHandle WinHttpOpenRequest( SafeWinHttpHandle connectHandle, string verb, string objectName, string version, string referrer, string acceptTypes, uint flags);
public static void DisposeAndClearHandle(ref SafeWinHttpHandle safeHandle) { if (safeHandle != null) { safeHandle.Dispose(); safeHandle = null; } }
public static extern bool WinHttpQueryHeaders( #endif SafeWinHttpHandle requestHandle, uint infoLevel, string name, IntPtr buffer, ref uint bufferLength, ref uint index);
public static void DisposeAndClearHandle(ref SafeWinHttpHandle winHttpHandler) { if (winHttpHandler != null) { winHttpHandler.Dispose(); winHttpHandler = null; } }
public static partial bool WinHttpSendRequest( SafeWinHttpHandle requestHandle, IntPtr headers, uint headersLength, IntPtr optional, uint optionalLength, uint totalLength, IntPtr context);
public static extern SafeWinHttpHandleWithCallback WinHttpOpenRequestWithCallback( SafeWinHttpHandle connectHandle, string verb, string objectName, string version, string referrer, string acceptTypes, uint flags);
// Important: WinHttp API calls should not happen while another WinHttp call for the same handle did not // return. During finalization that was not initiated by the Dispose pattern we don't expect any other WinHttp // calls in progress. protected override bool ReleaseHandle() { if (_parentHandle != null) { _parentHandle.DangerousRelease(); _parentHandle = null; } return(Interop.WinHttp.WinHttpCloseHandle(handle)); }
// Important: WinHttp API calls should not happen while another WinHttp call for the same handle did not // return. During finalization that was not initiated by the Dispose pattern we don't expect any other WinHttp // calls in progress. protected override bool ReleaseHandle() { if (_parentHandle != null) { _parentHandle.DangerousRelease(); _parentHandle = null; } // TODO(Issue 2500): Add logging so we know when the handle gets closed. return(Interop.WinHttp.WinHttpCloseHandle(handle)); }
// Important: WinHttp API calls should not happen while another WinHttp call for the same handle did not // return. During finalization that was not initiated by the Dispose pattern we don't expect any other WinHttp // calls in progress. protected override bool ReleaseHandle() { if (_parentHandle != null) { _parentHandle.DangerousRelease(); _parentHandle = null; } // TODO(Issue 2500): Add logging so we know when the handle gets closed. return Interop.WinHttp.WinHttpCloseHandle(handle); }
public void SetParentHandle(SafeWinHttpHandle parentHandle) { Debug.Assert(_parentHandle == null); Debug.Assert(parentHandle != null); Debug.Assert(!parentHandle.IsInvalid); bool ignore = false; parentHandle.DangerousAddRef(ref ignore); _parentHandle = parentHandle; }
private uint CalculateHeaderBufferSize(SafeWinHttpHandle hRequest) { uint bufferLengthInBytes = 0; uint index = 0; if (!WinHttpQueryHeaders( hRequest, WINHTTP_QUERY_RAW_HEADERS_CRLF, WINHTTP_HEADER_NAME_BY_INDEX, IntPtr.Zero, ref bufferLengthInBytes, ref index) && Marshal.GetLastWin32Error() == ERROR_INSUFFICIENT_BUFFER) { return(bufferLengthInBytes); } return(0); }
private string GetHeaders(SafeWinHttpHandle hRequest, uint bufferLengthInBytes) { uint index = 0; var pBuf = Marshal.AllocHGlobal((int)bufferLengthInBytes); if (!WinHttpQueryHeaders( hRequest, WINHTTP_QUERY_RAW_HEADERS_CRLF, WINHTTP_HEADER_NAME_BY_INDEX, pBuf, ref bufferLengthInBytes, ref index)) { throw new IOException("Unable to read headers: " + Marshal.GetLastWin32Error()); } Log.Debug("Header len after read: " + bufferLengthInBytes); var header = Marshal.PtrToStringAuto(pBuf); Marshal.FreeHGlobal(pBuf); return(header); }
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); }
public static extern SafeWinHttpHandleWithCallback WinHttpConnectWithCallback( SafeWinHttpHandle sessionHandle, string serverName, ushort serverPort, uint reserved);
public static extern bool WinHttpQueryOption( SafeWinHttpHandle handle, uint option, IntPtr buffer, ref uint bufferSize);
public static extern uint WinHttpWebSocketClose( SafeWinHttpHandle webSocketHandle, ushort status, IntPtr reason, uint reasonLength);
public static extern uint WinHttpWebSocketQueryCloseStatus( SafeWinHttpHandle webSocketHandle, out ushort status, byte[] reason, uint reasonLength, out uint reasonLengthConsumed);
public static extern bool WinHttpSetOption( SafeWinHttpHandle handle, uint option, IntPtr optionData, uint optionLength);
public static extern uint WinHttpWebSocketShutdown( SafeWinHttpHandle webSocketHandle, ushort status, byte[] reason, uint reasonLength);
public static extern bool WinHttpWriteData( SafeWinHttpHandle requestHandle, IntPtr buffer, uint bufferSize, IntPtr parameterIgnoredAndShouldBeNullForAsync);
public static extern bool WinHttpReceiveResponse( SafeWinHttpHandle requestHandle, IntPtr reserved);
public static extern bool WinHttpReadData( SafeWinHttpHandle requestHandle, IntPtr buffer, uint bufferSize, out uint bytesRead);
public static extern bool WinHttpQueryDataAvailable( SafeWinHttpHandle requestHandle, IntPtr parameterIgnoredAndShouldBeNullForAsync);
public static extern IntPtr WinHttpSetStatusCallback( SafeWinHttpHandle handle, WINHTTP_STATUS_CALLBACK callback, uint notificationFlags, IntPtr reserved);
public static extern bool WinHttpSetTimeouts( SafeWinHttpHandle handle, int resolveTimeout, int connectTimeout, int sendTimeout, int receiveTimeout);
public static extern bool WinHttpAddRequestHeaders( SafeWinHttpHandle requestHandle, string headers, uint headersLength, uint modifiers);
public static extern bool WinHttpWriteData( SafeWinHttpHandle requestHandle, IntPtr buffer, uint bufferSize, out uint bytesWritten);
public static extern bool WinHttpQueryDataAvailable( SafeWinHttpHandle requestHandle, out uint bytesAvailable);
public static extern bool WinHttpQueryOption( SafeWinHttpHandle handle, uint option, [Out] StringBuilder buffer, ref uint bufferSize);
public static extern bool WinHttpQueryOption( SafeWinHttpHandle handle, uint option, ref uint buffer, ref uint bufferSize);
public static extern uint WinHttpWebSocketSend( SafeWinHttpHandle webSocketHandle, WINHTTP_WEB_SOCKET_BUFFER_TYPE bufferType, IntPtr buffer, uint bufferLength);
public static extern uint WinHttpWebSocketReceive( SafeWinHttpHandle webSocketHandle, IntPtr buffer, uint bufferLength, out uint bytesRead, out WINHTTP_WEB_SOCKET_BUFFER_TYPE bufferType);
public static extern bool WinHttpSetOption( SafeWinHttpHandle handle, uint option, ref uint optionData, uint optionLength = sizeof(uint));
public static extern bool WinHttpQueryHeaders( SafeWinHttpHandle requestHandle, uint infoLevel, string name, ref uint number, ref uint bufferLength, IntPtr index);
public static extern bool WinHttpQueryAuthSchemes( SafeWinHttpHandle requestHandle, out uint supportedSchemes, out uint firstScheme, out uint authTarget);
public static extern bool WinHttpSetCredentials( SafeWinHttpHandle requestHandle, uint authTargets, uint authScheme, string userName, string password, IntPtr reserved);
public static extern bool WinHttpGetProxyForUrl( SafeWinHttpHandle sessionHandle, string url, ref WINHTTP_AUTOPROXY_OPTIONS autoProxyOptions, out WINHTTP_PROXY_INFO proxyInfo);
public static extern SafeWinHttpHandle WinHttpConnect( SafeWinHttpHandle sessionHandle, string serverName, ushort serverPort, uint reserved);
public static extern bool WinHttpReadData( SafeWinHttpHandle requestHandle, IntPtr buffer, uint bufferSize, IntPtr parameterIgnoredAndShouldBeNullForAsync);
public static extern SafeWinHttpHandleWithCallback WinHttpWebSocketCompleteUpgrade( SafeWinHttpHandle requestHandle, IntPtr context);