using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Runtime.InteropServices; using System.Text; using Vanara.Extensions; using Vanara.InteropServices; using FILETIME = System.Runtime.InteropServices.ComTypes.FILETIME; namespace Vanara.PInvoke { /// Functions and structures from WinInet.dll. public static partial class WinINet { /// Uses the default port for FTP servers (port 21). public const ushort INTERNET_DEFAULT_FTP_PORT = 21; /// Uses the default port for Gopher servers (port 70). Note Windows XP and Windows Server 2003 R2 and earlier only. public const ushort INTERNET_DEFAULT_GOPHER_PORT = 70; /// Uses the default port for HTTP servers (port 80). public const ushort INTERNET_DEFAULT_HTTP_PORT = 80; /// Uses the default port for Secure Hypertext Transfer Protocol (HTTPS) servers (port 443). public const ushort INTERNET_DEFAULT_HTTPS_PORT = 443; /// Uses the default port for SOCKS firewall servers (port 1080). public const ushort INTERNET_DEFAULT_SOCKS_PORT = 1080; /// Uses the default port for the service specified by dwService. public const ushort INTERNET_INVALID_PORT_NUMBER = 0; /// public const int INTERNET_RFC1123_BUFSIZE = 30; /// Represents a failure occurred when calling . public static readonly IntPtr INTERNET_INVALID_STATUS_CALLBACK = (IntPtr)(-1); private const uint GOPHER_ATTRIBUTE_ID_BASE = 0xabcccc00; private const int INTERNET_MAX_HOST_NAME_LENGTH = 256; private const int INTERNET_MAX_PASSWORD_LENGTH = 128; private const int INTERNET_MAX_PATH_LENGTH = 2048; private const int INTERNET_MAX_PORT_NUMBER_LENGTH = 5; private const int INTERNET_MAX_PORT_NUMBER_VALUE = 65535; private const int INTERNET_MAX_SCHEME_LENGTH = 32; private const int INTERNET_MAX_URL_LENGTH = INTERNET_MAX_SCHEME_LENGTH + 3 /* sizeof("://") */ + INTERNET_MAX_PATH_LENGTH; private const int INTERNET_MAX_USER_NAME_LENGTH = 128; /// /// [The GopherAttributeEnumerator function is available for use in the operating systems specified in the Requirements section.] /// /// Prototype for a callback function that processes attribute information from a Gopher server. This callback function is installed /// by a call to the GopherGetAttribute function. /// /// /// The GOPHER_ATTRIBUTE_ENUMERATOR type defines a pointer to this callback function. GopherAttributeEnumerator is a /// placeholder for the application-defined function name. /// /// /// /// Note WinINet does not support server implementations. In addition, it should not be used from a service. For server /// implementations or services use Microsoft Windows HTTP Services (WinHTTP). /// // https://docs.microsoft.com/en-us/windows/win32/api/wininet/nc-wininet-gopher_attribute_enumerator GOPHER_ATTRIBUTE_ENUMERATOR // GopherAttributeEnumerator; BOOL GopherAttributeEnumerator( LPGOPHER_ATTRIBUTE_TYPE lpAttributeInfo, DWORD dwError ) {...} [PInvokeData("wininet.h", MSDNShortId = "1a319d79-7866-4121-a80f-22e3bf983a0a")] [UnmanagedFunctionPointer(CallingConvention.Winapi)] public delegate BOOL GopherAttributeEnumerator(in GOPHER_ATTRIBUTE_TYPE lpAttributeInfo, Win32Error dwError); /// Callback for . /// The context specified in the structure. /// The error code: success, resend, or cancel. /// Reserved. Will always be IntPtr.Zero. /// Error?? (undocumented) [UnmanagedFunctionPointer(CallingConvention.Winapi)] public delegate uint InternetAuthNotifyCallback(IntPtr dwContext, Win32Error dwReturn, IntPtr lpReserved); /// Prototype for an application-defined status callback function. /// The handle for which the callback function is called. /// A pointer to a variable that specifies the application-defined context value associated with hInternet. /// A status code that indicates why the callback function is called. /// /// A pointer to additional status information. When the INTERNET_STATUS_STATE_CHANGE flag is set, lpvStatusInformation points to a /// DWORD that contains one or more of the flags. /// /// The size, in bytes, of the data pointed to by lpvStatusInformation. [PInvokeData("wininet.h", MSDNShortId = "a054fb71-66ab-46fd-be19-2237f05662bc")] [UnmanagedFunctionPointer(CallingConvention.Winapi)] public delegate void InternetStatusCallback([In] HINTERNET hInternet, [In, Optional] IntPtr dwContext, [In] InternetStatus dwInternetStatus, [In, Optional] IntPtr lpvStatusInformation, [In] uint dwStatusInformationLength); /// Indicates the members that are to be retrieved via . [PInvokeData("winineti.h", MSDNShortId = "93a29a4f-57bf-497c-a7b1-3960935590f9")] [Flags] public enum CACHE_CONFIG_FC : uint { /// Not used. CACHE_CONFIG_FORCE_CLEANUP_FC = 0x00000020, /// Not used. CACHE_CONFIG_DISK_CACHE_PATHS_FC = 0x00000040, /// Reserved. CACHE_CONFIG_SYNC_MODE_FC = 0x00000080, /// /// The CachePath field of the INTERNET_CACHE_CONFIG_INFO structure specified in the lpCachedConfigInfo parameter is filled with /// a pointer to a string identifying the content path. This cannot be used at the same time as CACHE_CONFIG_HISTORY_PATHS_FC or CACHE_CONFIG_COOKIES_PATHS_FC. /// CACHE_CONFIG_CONTENT_PATHS_FC = 0x00000100, /// /// The CachePath field of the INTERNET_CACHE_CONFIG_INFO structure specified in the lpCachedConfigInfo parameter is filled with /// a pointer to a string identifying the cookie path. This cannot be used at the same time as CACHE_CONFIG_CONTENT_PATHS_FC or CACHE_CONFIG_HISTORY_PATHS_FC. /// CACHE_CONFIG_COOKIES_PATHS_FC = 0x00000200, /// /// The CachePath field of the INTERNET_CACHE_CONFIG_INFO structure specified in the lpCachedConfigInfo parameter is filled with /// a pointer to a string identifying the history path. This cannot be used at the same time as CACHE_CONFIG_CONTENT_PATHS_FC or CACHE_CONFIG_COOKIES_PATHS_FC. /// CACHE_CONFIG_HISTORY_PATHS_FC = 0x00000400, /// /// The dwQuota field of the INTERNET_CACHE_CONFIG_INFO structure specified in the lpCachedConfigInfo is set to the cache limit /// for the container specified in the dwContainer field. /// CACHE_CONFIG_QUOTA_FC = 0x00000800, /// Reserved. CACHE_CONFIG_USER_MODE_FC = 0x00001000, /// /// The dwNormalUsage field of the INTERNET_CACHE_CONFIG_INFO structure specified in the lpCachedConfigInfo is set to the cache /// size for the container specified in the dwContainer field. /// CACHE_CONFIG_CONTENT_USAGE_FC = 0x00002000, /// /// The dwExemptUsage field of the INTERNET_CACHE_CONFIG_INFO structure specified in the lpCachedConfigInfo is set to the exempt /// usage, the amount of bytes exempt from scavenging, for the container specified in the dwContainer field. (This field must be /// the content container.) /// CACHE_CONFIG_STICKY_CONTENT_USAGE_FC = 0x00004000, } /// Indicates the members that are to be set via . [PInvokeData("wininet.h", MSDNShortId = "71f6e1a3-09ce-4576-9480-1270f343db39")] [Flags] public enum CACHE_ENTRY_FC : uint { /// Sets the cache entry type. CACHE_ENTRY_ATTRIBUTE_FC = 0x00000004, /// Sets the hit rate. CACHE_ENTRY_HITRATE_FC = 0x00000010, /// Sets the last modified time. CACHE_ENTRY_MODTIME_FC = 0x00000040, /// Sets the expire time. CACHE_ENTRY_EXPTIME_FC = 0x00000080, /// Sets the last access time. CACHE_ENTRY_ACCTIME_FC = 0x00000100, /// Sets the last sync time. CACHE_ENTRY_SYNCTIME_FC = 0x00000200, /// Not currently implemented. CACHE_ENTRY_HEADERINFO_FC = 0x00000400, /// Sets the exempt delta. CACHE_ENTRY_EXEMPT_DELTA_FC = 0x00000800, } /// A bitmask indicating the type of cache entry and its properties. [PInvokeData("wininet.h", MSDNShortId = "7bda08e0-5df0-4087-a5cd-3a25c6ae5ade")] [Flags] public enum CACHE_ENTRY_TYPE { /// The default filter. URLCACHE_FIND_DEFAULT_FILTER = NORMAL_CACHE_ENTRY | COOKIE_CACHE_ENTRY | URLHISTORY_CACHE_ENTRY | TRACK_OFFLINE_CACHE_ENTRY | TRACK_ONLINE_CACHE_ENTRY | STICKY_CACHE_ENTRY, /// Normal cache entry; can be deleted to recover space for new entries. NORMAL_CACHE_ENTRY = 0x00000001, /// /// Sticky cache entry that is exempt from scavenging for the amount of time specified by dwExemptDelta. The default value set /// by CommitUrlCacheEntryA and CommitUrlCacheEntryW is one day. /// STICKY_CACHE_ENTRY = 0x00000004, /// Cache entry file that has been edited externally. This cache entry type is exempt from scavenging. EDITED_CACHE_ENTRY = 0x00000008, /// Not currently implemented. TRACK_OFFLINE_CACHE_ENTRY = 0x00000010, /// Not currently implemented. TRACK_ONLINE_CACHE_ENTRY = 0x00000020, /// Partial response cache entry. SPARSE_CACHE_ENTRY = 0x00010000, /// Cookie cache entry. COOKIE_CACHE_ENTRY = 0x00100000, /// Visited link cache entry. URLHISTORY_CACHE_ENTRY = 0x00200000, } /// Cache group flgas. [PInvokeData("wininet.h")] public enum CACHEGROUP_FLAG { /// Indicates that the cache entries in this group will not be removed by the cache manager. CACHEGROUP_FLAG_NONPURGEABLE = 0x00000001, /// Causes CreateUrlCacheGroup to generate a unique GROUPID, but does not create a physical group. CACHEGROUP_FLAG_GIDONLY = 0x00000004, /// /// Causes DeleteUrlCacheGroup to delete all of the cache entries associated with this group, unless the entry belongs to /// another group. /// CACHEGROUP_FLAG_FLUSHURL_ONDELETE = 0x00000002, } /// Filters for . [PInvokeData("wininet.h", MSDNShortId = "a333cbc6-a880-4b1c-be0d-abb083909638")] public enum CACHEGROUP_SEARCH { /// Search all cache groups. CACHEGROUP_SEARCH_ALL, /// Not currently implemented. CACHEGROUP_SEARCH_BYURL } /// Options for . [PInvokeData("wininet.h", MSDNShortId = "4666e4ee-057e-452d-ac2c-d03321a0073f")] [Flags] public enum FLAG_ICC { /// Forces a connection. FLAG_ICC_FORCE_CONNECTION = 1 } /// Actions to perform when calling . [PInvokeData("wininet.h", MSDNShortId = "09384ba9-e5cc-48fd-a52c-15df223f87dc")] [Flags] public enum FLAGS_ERROR_UI { /// /// Scans the returned headers for errors. Call InternetErrorDlg with this flag set following a call to HttpSendRequest so as to /// detect hidden errors. Authentication errors, for example, are normally hidden because the call to HttpSendRequest completes /// successfully, but by scanning the status codes, InternetErrorDlg can determine that the proxy or server requires authentication. /// FLAGS_ERROR_UI_FILTER_FOR_ERRORS = 0x01, /// If the function succeeds, stores the results of the dialog box in the Internet handle. FLAGS_ERROR_UI_FLAGS_CHANGE_OPTIONS = 0x02, /// /// Queries the Internet handle for needed information. The function constructs the appropriate data structure for the error. /// (For example, for Cert CN failures, the function grabs the certificate.) /// FLAGS_ERROR_UI_FLAGS_GENERATE_DATA = 0x04, /// /// Allows the caller to pass NULL to the hWnd parameter without error. To be used in circumstances in which no user interface /// is required. /// FLAGS_ERROR_UI_FLAGS_NO_UI = 0x08, /// /// Serializes authentication dialog boxes for concurrent requests on a password cache entry. The lppvData parameter should /// contain the address of a pointer to an INTERNET_AUTH_NOTIFY_DATA structure, and the client should implement a thread-safe, /// non-blocking callback function. /// FLAGS_ERROR_UI_SERIALIZE_DIALOGS = 0x10, } /// Transfer types for FTP transfers. [PInvokeData("wininet.h", MSDNShortId = "cd12f52c-80d6-4aee-96c8-cb3cafcf0a6a")] public enum FTP_TRANSER_TYPE : uint { /// /// Transfers the file using the FTP Image (Type I) transfer method. The file is transferred exactly with no changes. This is /// the default transfer method. /// FTP_TRANSER_TYPE_BINARY = INTERNET_FLAG.INTERNET_FLAG_TRANSFER_BINARY, /// /// Transfers the file using the FTP ASCII (Type A) transfer method. Control and formatting data is converted to local equivalents. /// FTP_TRANSER_TYPE_ASCII = INTERNET_FLAG.INTERNET_FLAG_TRANSFER_ASCII } /// Attribute type. [PInvokeData("wininet.h", MSDNShortId = "01daae8c-9080-4a8d-9f73-3e364ca868fe")] public enum GOPHER_ATTRIBUTE_ID : uint { /// GOPHER_ATTRIBUTE_ID_ADMIN = GOPHER_ATTRIBUTE_ID_BASE + 10, /// GOPHER_ATTRIBUTE_ID_MOD_DATE = GOPHER_ATTRIBUTE_ID_BASE + 11, /// GOPHER_ATTRIBUTE_ID_TTL = GOPHER_ATTRIBUTE_ID_BASE + 12, /// GOPHER_ATTRIBUTE_ID_SCORE = GOPHER_ATTRIBUTE_ID_BASE + 13, /// GOPHER_ATTRIBUTE_ID_RANGE = GOPHER_ATTRIBUTE_ID_BASE + 14, /// GOPHER_ATTRIBUTE_ID_SITE = GOPHER_ATTRIBUTE_ID_BASE + 15, /// GOPHER_ATTRIBUTE_ID_ORG = GOPHER_ATTRIBUTE_ID_BASE + 16, /// GOPHER_ATTRIBUTE_ID_LOCATION = GOPHER_ATTRIBUTE_ID_BASE + 17, /// GOPHER_ATTRIBUTE_ID_GEOG = GOPHER_ATTRIBUTE_ID_BASE + 18, /// GOPHER_ATTRIBUTE_ID_TIMEZONE = GOPHER_ATTRIBUTE_ID_BASE + 19, /// GOPHER_ATTRIBUTE_ID_PROVIDER = GOPHER_ATTRIBUTE_ID_BASE + 20, /// GOPHER_ATTRIBUTE_ID_VERSION = GOPHER_ATTRIBUTE_ID_BASE + 21, /// GOPHER_ATTRIBUTE_ID_ABSTRACT = GOPHER_ATTRIBUTE_ID_BASE + 22, /// GOPHER_ATTRIBUTE_ID_VIEW = GOPHER_ATTRIBUTE_ID_BASE + 23, /// GOPHER_ATTRIBUTE_ID_TREEWALK = GOPHER_ATTRIBUTE_ID_BASE + 24, /// GOPHER_ATTRIBUTE_ID_UNKNOWN = GOPHER_ATTRIBUTE_ID_BASE + 25, } /// Name of the Gopher category for the attribute. [PInvokeData("wininet.h", MSDNShortId = "01daae8c-9080-4a8d-9f73-3e364ca868fe")] public enum GOPHER_CATEGORY_ID : uint { /// GOPHER_CATEGORY_ID_INFO = GOPHER_ATTRIBUTE_ID_BASE + 2, /// GOPHER_CATEGORY_ID_ADMIN = GOPHER_ATTRIBUTE_ID_BASE + 3, /// GOPHER_CATEGORY_ID_VIEWS = GOPHER_ATTRIBUTE_ID_BASE + 4, /// GOPHER_CATEGORY_ID_ABSTRACT = GOPHER_ATTRIBUTE_ID_BASE + 5, /// GOPHER_CATEGORY_ID_VERONICA = GOPHER_ATTRIBUTE_ID_BASE + 6, /// GOPHER_CATEGORY_ID_ASK = GOPHER_ATTRIBUTE_ID_BASE + 7, /// GOPHER_CATEGORY_ID_UNKNOWN = GOPHER_ATTRIBUTE_ID_BASE + 8, } /// Gopher types. [PInvokeData("wininet.h")] [Flags] public enum GOPHER_TYPE : uint { /// Ask+ item. GOPHER_TYPE_ASK = 0x40000000, /// Binary file. GOPHER_TYPE_BINARY = 0x00000200, /// Bitmap file. GOPHER_TYPE_BITMAP = 0x00004000, /// Calendar file. GOPHER_TYPE_CALENDAR = 0x00080000, /// CSO telephone book server. GOPHER_TYPE_CSO = 0x00000004, /// Directory of additional Gopher items. GOPHER_TYPE_DIRECTORY = 0x00000002, /// MS-DOS archive file. GOPHER_TYPE_DOS_ARCHIVE = 0x00000020, /// Indicator of an error condition. GOPHER_TYPE_ERROR = 0x00000008, /// GIF graphics file. GOPHER_TYPE_GIF = 0x00001000, /// Gopher+ item. GOPHER_TYPE_GOPHER_PLUS = 0x80000000, /// HTML document. GOPHER_TYPE_HTML = 0x00020000, /// Image file. GOPHER_TYPE_IMAGE = 0x00002000, /// Index server. GOPHER_TYPE_INDEX_SERVER = 0x00000080, /// Inline file. GOPHER_TYPE_INLINE = 0x00100000, /// Macintosh file in BINHEX format. GOPHER_TYPE_MAC_BINHEX = 0x00000010, /// Movie file. GOPHER_TYPE_MOVIE = 0x00008000, /// PDF file. GOPHER_TYPE_PDF = 0x00040000, /// /// Indicator of a duplicated server. The information contained within is a duplicate of the primary server. The primary server /// is defined as the last directory entry that did not have a GOPHER_TYPE_REDUNDANT type. /// GOPHER_TYPE_REDUNDANT = 0x00000400, /// Sound file. GOPHER_TYPE_SOUND = 0x00010000, /// Telnet server. GOPHER_TYPE_TELNET = 0x00000100, /// ASCII text file. GOPHER_TYPE_TEXT_FILE = 0x00000001, /// TN3270 server. GOPHER_TYPE_TN3270 = 0x00000800, /// UUENCODED file. GOPHER_TYPE_UNIX_UUENCODED = 0x00000040, /// Item type is unknown. GOPHER_TYPE_UNKNOWN = 0x20000000, } /// A set of modifiers that control the semantics of . [PInvokeData("wininet.h", MSDNShortId = "636c3442-a2e6-4885-8fb4-1f6996ba6860")] [Flags] public enum HTTP_ADDREQ_FLAG : uint { /// Adds the header only if it does not already exist; otherwise, an error is returned. HTTP_ADDREQ_FLAG_ADD_IF_NEW = 0x10000000, /// Adds the header if it does not exist. Used with HTTP_ADDREQ_FLAG_REPLACE. HTTP_ADDREQ_FLAG_ADD = 0x20000000, /// /// Coalesces headers of the same name. For example, adding "Accept: text/*" followed by "Accept: audio/*" with this flag /// results in the formation of the single header "Accept: text/*, audio/*". This causes the first header found to be coalesced. /// It is up to the calling application to ensure a cohesive scheme with respect to coalesced/separate headers. /// HTTP_ADDREQ_FLAG_COALESCE_WITH_COMMA = 0x40000000, /// Coalesces headers of the same name using a semicolon. HTTP_ADDREQ_FLAG_COALESCE_WITH_SEMICOLON = 0x01000000, /// Coalesces headers of the same name. HTTP_ADDREQ_FLAG_COALESCE = HTTP_ADDREQ_FLAG_COALESCE_WITH_COMMA, /// /// Replaces or removes a header. If the header value is empty and the header is found, it is removed. If not empty, the header /// value is replaced. /// HTTP_ADDREQ_FLAG_REPLACE = 0x80000000 } /// /// The attribute flags are used by HttpQueryInfo (or QueryInfo) to indicate what data to retrieve. Most of the attribute flags map /// directly to a specific HTTP header. There are also some special flags, such as HTTP_QUERY_RAW_HEADERS, that are not related to a /// specific header. /// [PInvokeData("wininet.h")] [Flags] public enum HTTP_QUERY : uint { /// Retrieves the acceptable media types for the response. HTTP_QUERY_ACCEPT = 24, /// Retrieves the acceptable character sets for the response. HTTP_QUERY_ACCEPT_CHARSET = 25, /// Retrieves the acceptable content-coding values for the response. HTTP_QUERY_ACCEPT_ENCODING = 26, /// Retrieves the acceptable natural languages for the response. HTTP_QUERY_ACCEPT_LANGUAGE = 27, /// Retrieves the types of range requests that are accepted for a resource. HTTP_QUERY_ACCEPT_RANGES = 42, /// /// Retrieves the Age response-header field, which contains the sender's estimate of the amount of time since the response was /// generated at the origin server. /// HTTP_QUERY_AGE = 48, /// Receives the HTTP verbs supported by the server. HTTP_QUERY_ALLOW = 7, /// Retrieves the authorization credentials used for a request. HTTP_QUERY_AUTHORIZATION = 28, /// Retrieves the cache control directives. HTTP_QUERY_CACHE_CONTROL = 49, /// /// Retrieves any options that are specified for a particular connection and must not be communicated by proxies over further connections. /// HTTP_QUERY_CONNECTION = 23, /// Retrieves the base URI (Uniform Resource Identifier) for resolving relative URLs within the entity. HTTP_QUERY_CONTENT_BASE = 50, /// Obsolete. Maintained for legacy application compatibility only. HTTP_QUERY_CONTENT_DESCRIPTION = 4, /// Obsolete. Maintained for legacy application compatibility only. HTTP_QUERY_CONTENT_DISPOSITION = 47, /// Retrieves any additional content codings that have been applied to the entire resource. HTTP_QUERY_CONTENT_ENCODING = 29, /// Retrieves the content identification. HTTP_QUERY_CONTENT_ID = 3, /// Retrieves the language that the content is in. HTTP_QUERY_CONTENT_LANGUAGE = 6, /// Retrieves the size of the resource, in bytes. HTTP_QUERY_CONTENT_LENGTH = 5, /// Retrieves the resource location for the entity enclosed in the message. HTTP_QUERY_CONTENT_LOCATION = 51, /// /// Retrieves an MD5 digest of the entity-body for the purpose of providing an end-to-end message integrity check (MIC) for the /// entity-body. For more information, see RFC1864, The Content-MD5 Header Field, at https://ftp.isi.edu/in-notes/rfc1864.txt. /// HTTP_QUERY_CONTENT_MD5 = 52, /// /// Retrieves the location in the full entity-body where the partial entity-body should be inserted and the total size of the /// full entity-body. /// HTTP_QUERY_CONTENT_RANGE = 53, /// Receives the additional content coding that has been applied to the resource. HTTP_QUERY_CONTENT_TRANSFER_ENCODING = 2, /// Receives the content type of the resource (such as text/html). HTTP_QUERY_CONTENT_TYPE = 1, /// Retrieves any cookies associated with the request. HTTP_QUERY_COOKIE = 44, /// No longer supported. HTTP_QUERY_COST = 15, /// Causes HttpQueryInfo to search for the header name specified in lpvBuffer and store the header data in lpvBuffer. HTTP_QUERY_CUSTOM = 65535, /// Receives the date and time at which the message was originated. HTTP_QUERY_DATE = 9, /// No longer supported. HTTP_QUERY_DERIVED_FROM = 14, /// Not currently implemented. HTTP_QUERY_ECHO_HEADERS = 73, /// Not currently implemented. HTTP_QUERY_ECHO_HEADERS_CRLF = 74, /// Not currently implemented. HTTP_QUERY_ECHO_REPLY = 72, /// Not currently implemented. HTTP_QUERY_ECHO_REQUEST = 71, /// Retrieves the entity tag for the associated entity. HTTP_QUERY_ETAG = 54, /// Retrieves the Expect header, which indicates whether the client application should expect 100 series responses. HTTP_QUERY_EXPECT = 68, /// Receives the date and time after which the resource should be considered outdated. HTTP_QUERY_EXPIRES = 10, /// Obsolete. Maintained for legacy application compatibility only. HTTP_QUERY_FORWARDED = 30, /// /// Retrieves the email address for the human user who controls the requesting user agent if the From header is given. /// HTTP_QUERY_FROM = 31, /// Retrieves the Internet host and port number of the resource being requested. HTTP_QUERY_HOST = 55, /// Retrieves the contents of the If-Match request-header field. HTTP_QUERY_IF_MATCH = 56, /// Retrieves the contents of the If-Modified-Since header. HTTP_QUERY_IF_MODIFIED_SINCE = 32, /// Retrieves the contents of the If-None-Match request-header field. HTTP_QUERY_IF_NONE_MATCH = 57, /// /// Retrieves the contents of the If-Range request-header field. This header enables the client application to verify that the /// entity related to a partial copy of the entity in the client application cache has not been updated. If the entity has not /// been updated, send the parts that the client application is missing. If the entity has been updated, send the entire updated entity. /// HTTP_QUERY_IF_RANGE = 58, /// Retrieves the contents of the If-Unmodified-Since request-header field. HTTP_QUERY_IF_UNMODIFIED_SINCE = 59, /// Receives the date and time at which the server believes the resource was last modified. HTTP_QUERY_LAST_MODIFIED = 11, /// Obsolete. Maintained for legacy application compatibility only. HTTP_QUERY_LINK = 16, /// Retrieves the absolute Uniform Resource Identifier (URI) used in a Location response-header. HTTP_QUERY_LOCATION = 33, /// Not a query flag. Indicates the maximum value of an HTTP_QUERY_* value. HTTP_QUERY_MAX = 78, /// Retrieves the number of proxies or gateways that can forward the request to the next inbound server. HTTP_QUERY_MAX_FORWARDS = 60, /// No longer supported. HTTP_QUERY_MESSAGE_ID = 12, /// Receives the version of the MIME protocol that was used to construct the message. HTTP_QUERY_MIME_VERSION = 0, /// Obsolete. Maintained for legacy application compatibility only. HTTP_QUERY_ORIG_URI = 34, /// /// Receives the implementation-specific directives that might apply to any recipient along the request/response chain. /// HTTP_QUERY_PRAGMA = 17, /// Retrieves the authentication scheme and realm returned by the proxy. HTTP_QUERY_PROXY_AUTHENTICATE = 41, /// /// Retrieves the header that is used to identify the user to a proxy that requires authentication. This header can only be /// retrieved before the request is sent to the server. /// HTTP_QUERY_PROXY_AUTHORIZATION = 61, /// Retrieves the Proxy-Connection header. HTTP_QUERY_PROXY_CONNECTION = 69, /// Receives methods available at this server. HTTP_QUERY_PUBLIC = 8, /// Retrieves the byte range of an entity. HTTP_QUERY_RANGE = 62, /// /// Receives all the headers returned by the server. Each header is terminated by "\0". An additional "\0" terminates the list /// of headers. /// HTTP_QUERY_RAW_HEADERS = 21, /// /// Receives all the headers returned by the server. Each header is separated by a carriage return/line feed (CR/LF) sequence. /// HTTP_QUERY_RAW_HEADERS_CRLF = 22, /// Receives the Uniform Resource Identifier (URI) of the resource where the requested URI was obtained. HTTP_QUERY_REFERER = 35, /// Obsolete. Maintained for legacy application compatibility only. HTTP_QUERY_REFRESH = 46, /// Receives the HTTP verb that is being used in the request, typically GET or POST. HTTP_QUERY_REQUEST_METHOD = 45, /// Retrieves the amount of time the service is expected to be unavailable. HTTP_QUERY_RETRY_AFTER = 36, /// Retrieves data about the software used by the origin server to handle the request. HTTP_QUERY_SERVER = 37, /// Receives the value of the cookie set for the request. HTTP_QUERY_SET_COOKIE = 43, /// /// Receives the status code returned by the server. For more information and a list of possible values, see HTTP Status Codes. /// HTTP_QUERY_STATUS_CODE = 19, /// Receives any additional text returned by the server on the response line. HTTP_QUERY_STATUS_TEXT = 20, /// Obsolete. Maintained for legacy application compatibility only. HTTP_QUERY_TITLE = 38, /// /// Retrieves the type of transformation that has been applied to the message body so it can be safely transferred between the /// sender and recipient. /// HTTP_QUERY_TRANSFER_ENCODING = 63, /// Retrieves the Unless-Modified-Since header. HTTP_QUERY_UNLESS_MODIFIED_SINCE = 70, /// Retrieves the additional communication protocols that are supported by the server. HTTP_QUERY_UPGRADE = 64, /// Receives some or all of the Uniform Resource Identifiers (URIs) by which the Request-URI resource can be identified. HTTP_QUERY_URI = 13, /// Retrieves data about the user agent that made the request. HTTP_QUERY_USER_AGENT = 39, /// /// Retrieves the header that indicates that the entity was selected from a number of available representations of the response /// using server-driven negotiation. /// HTTP_QUERY_VARY = 65, /// Receives the last response code returned by the server. HTTP_QUERY_VERSION = 18, /// /// Retrieves the intermediate protocols and recipients between the user agent and the server on requests, and between the /// origin server and the client on responses. /// HTTP_QUERY_VIA = 66, /// /// Retrieves additional data about the status of a response that might not be reflected by the response status code. /// HTTP_QUERY_WARNING = 67, /// Retrieves the authentication scheme and realm returned by the server. HTTP_QUERY_WWW_AUTHENTICATE = 40, /// Retrieves the X-Content-Type-Options header value. HTTP_QUERY_X_CONTENT_TYPE_OPTIONS = 79, /// Retrieves the P3P header value. HTTP_QUERY_P3P = 80, /// Retrieves the X-P2P-PeerDist header value. HTTP_QUERY_X_P2P_PEERDIST = 81, /// Retrieves the translate header value. HTTP_QUERY_TRANSLATE = 82, /// Retrieves the X-UA-Compatible header value. HTTP_QUERY_X_UA_COMPATIBLE = 83, /// Retrieves the Default-Style header value. HTTP_QUERY_DEFAULT_STYLE = 84, /// Retrieves the X-Frame-Options header value. HTTP_QUERY_X_FRAME_OPTIONS = 85, /// /// Retrieves the X-XSS-Protection header value. /// /// The modifier flags are used in conjunction with an attribute flag to modify the request. Modifier flags either modify the /// format of the data returned or indicate where HttpQueryInfo (or QueryInfo) should search for the data. /// /// HTTP_QUERY_X_XSS_PROTECTION = 86, /// Not implemented. HTTP_QUERY_FLAG_COALESCE = 0x10000000, /// Returns the data as a 32-bit number for headers whose value is a number, such as the status code. HTTP_QUERY_FLAG_NUMBER = 0x20000000, /// Queries request headers only. HTTP_QUERY_FLAG_REQUEST_HEADERS = 0x80000000, /// /// Returns the header value as a SYSTEMTIME structure, which does not require the application to parse the data. Use for /// headers whose value is a date/time string, such as "Last-Modified-Time". /// HTTP_QUERY_FLAG_SYSTEMTIME = 0x40000000, } /// Controls canonicalization. [PInvokeData("wininet.h", MSDNShortId = "3bfde980-e478-4960-b41f-e1c8105ef419")] [Flags] public enum ICU : uint { /// Does not convert unsafe characters to escape sequences. ICU_NO_ENCODE = 0x20000000, /// Converts all %XX sequences to characters, including escape sequences, before the URL is parsed. ICU_DECODE = 0x10000000, /// Does not remove meta sequences (such as "." and "..") from the URL. ICU_NO_META = 0x08000000, /// Encodes spaces only. ICU_ENCODE_SPACES_ONLY = 0x04000000, /// /// Does not encode or decode characters after "#" or "?", and does not remove trailing white space after "?". If this value is /// not specified, the entire URL is encoded and trailing white space is removed. /// ICU_BROWSER_MODE = 0x02000000, /// /// Encodes any percent signs encountered. By default, percent signs are not encoded. This value is available in Microsoft /// Internet Explorer 5 and later. /// ICU_ENCODE_PERCENT = 0x00001000, /// /// Converts all escape sequences (%xx) to their corresponding characters. This can be used only in InternetCrackUrl and /// InternetCreateUrl and if the user provides buffers in the URL_COMPONENTS structure to copy the components into. /// ICU_ESCAPE = 0x80000000, /// Obsolete — ignored. ICU_USERNAME = 0x40000000, } /// Flags used by . [PInvokeData("WinInet.h")] [Flags] public enum IDSI_Flags { /// Set if the connection is from the "keep-alive" pool. IDSI_FLAG_KEEP_ALIVE = 0x00000001, /// Set if the HTTP Request is using a secure socket. IDSI_FLAG_SECURE = 0x00000002, /// Set if a proxy is being used to reach the server. IDSI_FLAG_PROXY = 0x00000004, /// Set if a proxy is being used to create a tunnel. IDSI_FLAG_TUNNEL = 0x00000008 } /// Controls this operation of . [PInvokeData("wininet.h", MSDNShortId = "843875a8-6c83-4259-8e46-a04f786eb230")] [Flags] public enum INTERNET_AUTODIAL { /// /// Causes InternetAutodial to fail if file and printer sharing is disabled for Windows 95 or later. /// Windows Server 2008 and Windows Vista: This flag is obsolete. /// INTERNET_AUTODIAL_FAILIFSECURITYCHECK = 0x04, /// Forces an online Internet connection. INTERNET_AUTODIAL_FORCE_ONLINE = 0x01, /// Forces an unattended Internet dial-up. INTERNET_AUTODIAL_FORCE_UNATTENDED = 0x02, /// Causes InternetAutodial to dial the modem connection even when a network connection to the Internet is present. INTERNET_AUTODIAL_OVERRIDE_NET_PRESENT = 0x08, } /// Cache container flags. [PInvokeData("wininet.h")] [Flags] public enum INTERNET_CACHE_CONTAINER { /// INTERNET_CACHE_CONTAINER_NOSUBDIRS = 0x1, /// INTERNET_CACHE_CONTAINER_AUTODELETE = 0x2, /// INTERNET_CACHE_CONTAINER_RESERVED1 = 0x4, /// INTERNET_CACHE_CONTAINER_NODESKTOPINIT = 0x8, /// INTERNET_CACHE_CONTAINER_MAP_ENABLED = 0x10, /// INTERNET_CACHE_CONTAINER_BLOOM_FILTER = 0x20, /// INTERNET_CACHE_CONTAINER_SHARE_READ = 0x100, /// INTERNET_CACHE_CONTAINER_SHARE_READ_WRITE = 0x300, } /// Determines whether the entry is added to or removed from a cache group. [PInvokeData("wininet.h", MSDNShortId = "b39a96ac-c5b5-4b02-88e2-298a037be25f")] public enum INTERNET_CACHE_GROUP { /// Adds the cache entry to the cache group. INTERNET_CACHE_GROUP_ADD = 0, /// Removes the entry from the cache group. INTERNET_CACHE_GROUP_REMOVE = 1 } /// Internet connection state retrieved from . [PInvokeData("wininet.h", MSDNShortId = "500765b8-fbe4-4bba-894e-cc7f114d9eaa")] [Flags] public enum INTERNET_CONNECTION { /// Local system has a valid connection to the Internet, but it might or might not be currently connected. INTERNET_CONNECTION_CONFIGURED = 0x40, /// Local system uses a local area network to connect to the Internet. INTERNET_CONNECTION_LAN = 0x02, /// Local system uses a modem to connect to the Internet. INTERNET_CONNECTION_MODEM = 0x01, /// No longer used. INTERNET_CONNECTION_MODEM_BUSY = 0x08, /// Local system is in offline mode. INTERNET_CONNECTION_OFFLINE = 0x20, /// Local system uses a proxy server to connect to the Internet. INTERNET_CONNECTION_PROXY = 0x04, /// Local system has RAS installed. INTERNET_RAS_INSTALLED = 0x10, } /// Flags related to cookies. [PInvokeData("wininet.h")] [Flags] public enum INTERNET_COOKIE { /// INTERNET_COOKIE_IS_SECURE = 0x00000001, /// INTERNET_COOKIE_IS_SESSION = 0x00000002, /// Retrieves only third-party cookies if policy explicitly allows all cookies for the specified URL to be retrieved. INTERNET_COOKIE_THIRD_PARTY = 0x00000010, /// INTERNET_COOKIE_PROMPT_REQUIRED = 0x00000020, /// INTERNET_COOKIE_EVALUATE_P3P = 0x00000040, /// INTERNET_COOKIE_APPLY_P3P = 0x00000080, /// INTERNET_COOKIE_P3P_ENABLED = 0x00000100, /// INTERNET_COOKIE_IS_RESTRICTED = 0x00000200, /// INTERNET_COOKIE_IE6 = 0x00000400, /// INTERNET_COOKIE_IS_LEGACY = 0x00000800, /// INTERNET_COOKIE_NON_SCRIPT = 0x00001000, /// /// Enables the retrieval of cookies that are marked as "HTTPOnly". Do not use this flag if you expose a scriptable interface, /// because this has security implications. It is imperative that you use this flag only if you can guarantee that you will /// never expose the cookie to third-party code by way of an extensibility mechanism you provide. Version: Requires Internet /// Explorer 8.0 or later. /// INTERNET_COOKIE_HTTPONLY = 0x00002000, /// INTERNET_COOKIE_HOST_ONLY = 0x00004000, /// INTERNET_COOKIE_APPLY_HOST_ONLY = 0x00008000, /// INTERNET_COOKIE_HOST_ONLY_APPLIED = 0x00080000, /// INTERNET_COOKIE_SAME_SITE_STRICT = 0x00100000, /// INTERNET_COOKIE_SAME_SITE_LAX = 0x00200000, /// INTERNET_COOKIE_SAME_SITE_LEVEL_CROSS_SITE = 0x00400000, } /// Options for . [PInvokeData("wininet.h", MSDNShortId = "b8ce748b-9879-4f68-aea1-32e2bfaee8ab")] [Flags] public enum INTERNET_DIAL { /// Forces an online Internet connection. INTERNET_AUTODIAL_FORCE_ONLINE = 0x01, /// Forces an unattended Internet dial-up. INTERNET_AUTODIAL_FORCE_UNATTENDED = 0x02, /// Ignores the "dial automatically" setting and forces the dialing user interface to be displayed. INTERNET_DIAL_FORCE_PROMPT = 0x2000, /// Shows the Work Offline button instead of the Cancel button in the dialing user interface. INTERNET_DIAL_SHOW_OFFLINE = 0x4000, /// /// Connects to the Internet through a modem, without displaying a user interface, if possible. Otherwise, the function will /// wait for user input. /// INTERNET_DIAL_UNATTENDED = 0x8000, } /// Flags used for controlling connections [PInvokeData("WinInet.h")] [Flags] public enum INTERNET_FLAG : uint { /// retrieve the original item INTERNET_FLAG_RELOAD = 0x80000000, /// FTP/gopher find: receive the item as raw (structured) data INTERNET_FLAG_RAW_DATA = 0x40000000, /// FTP: use existing InternetConnect handle for server if possible INTERNET_FLAG_EXISTING_CONNECT = 0x20000000, /// this request is asynchronous (where supported) INTERNET_FLAG_ASYNC = 0x10000000, /// used for FTP connections INTERNET_FLAG_PASSIVE = 0x08000000, /// don't write this item to the cache INTERNET_FLAG_NO_CACHE_WRITE = 0x04000000, /// don't write this item to the cache INTERNET_FLAG_DONT_CACHE = 0x04000000, /// make this item persistent in cache INTERNET_FLAG_MAKE_PERSISTENT = 0x02000000, /// use offline semantics INTERNET_FLAG_FROM_CACHE = 0x01000000, /// use offline semantics INTERNET_FLAG_OFFLINE = 0x01000000, /// use PCT/SSL if applicable (HTTP) INTERNET_FLAG_SECURE = 0x00800000, /// use keep-alive semantics INTERNET_FLAG_KEEP_CONNECTION = 0x00400000, /// don't handle redirections automatically INTERNET_FLAG_NO_AUTO_REDIRECT = 0x00200000, /// do background read prefetch INTERNET_FLAG_READ_PREFETCH = 0x00100000, /// no automatic cookie handling INTERNET_FLAG_NO_COOKIES = 0x00080000, /// no automatic authentication handling INTERNET_FLAG_NO_AUTH = 0x00040000, /// return cache file if net request fails INTERNET_FLAG_CACHE_IF_NET_FAIL = 0x00010000, /// ex: https:// to http:// INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTP = 0x00008000, /// ex: http:// to https:// INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTPS = 0x00004000, /// expired X509 Cert. INTERNET_FLAG_IGNORE_CERT_DATE_INVALID = 0x00002000, /// bad common name in X509 Cert. INTERNET_FLAG_IGNORE_CERT_CN_INVALID = 0x00001000, /// asking wininet to update an item if it is newer INTERNET_FLAG_RESYNCHRONIZE = 0x00000800, /// asking wininet to do hyperlinking semantic which works right for scripts INTERNET_FLAG_HYPERLINK = 0x00000400, /// no cookie popup INTERNET_FLAG_NO_UI = 0x00000200, /// asking wininet to add "pragma: no-cache" INTERNET_FLAG_PRAGMA_NOCACHE = 0x00000100, /// ok to perform lazy cache-write INTERNET_FLAG_CACHE_ASYNC = 0x00000080, /// this is a forms submit INTERNET_FLAG_FORMS_SUBMIT = 0x00000040, /// fwd-back button op INTERNET_FLAG_FWD_BACK = 0x00000020, /// need a file for this request INTERNET_FLAG_NEED_FILE = 0x00000010, /// need a file for this request INTERNET_FLAG_MUST_CACHE_REQUEST = 0x00000010, /// INTERNET_FLAG_TRANSFER_ASCII = 0x00000001, /// INTERNET_FLAG_TRANSFER_BINARY = 0x00000002, } /// Option to be queried or set within structure. [PInvokeData("WinInet.h")] public enum INTERNET_PER_CONN_OPTION_ID { /// Sets or retrieves the connection type. [CorrespondingType(typeof(uint), CorrespondingAction.GetSet)] INTERNET_PER_CONN_FLAGS = 1, /// Sets or retrieves a string containing the proxy servers. [CorrespondingType(typeof(string), CorrespondingAction.GetSet)] INTERNET_PER_CONN_PROXY_SERVER = 2, /// Sets or retrieves a string containing the URLs that do not use the proxy server. [CorrespondingType(typeof(string), CorrespondingAction.GetSet)] INTERNET_PER_CONN_PROXY_BYPASS = 3, /// Sets or retrieves a string containing the URL to the automatic configuration script. [CorrespondingType(typeof(string), CorrespondingAction.GetSet)] INTERNET_PER_CONN_AUTOCONFIG_URL = 4, /// Sets or retrieves the automatic discovery settings. [CorrespondingType(typeof(uint), CorrespondingAction.GetSet)] INTERNET_PER_CONN_AUTODISCOVERY_FLAGS = 5, /// /// Chained autoconfig URL. Used when the primary autoconfig URL points to an INS file that sets a second autoconfig URL for /// proxy information. /// [CorrespondingType(typeof(string), CorrespondingAction.GetSet)] INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL = 6, /// The number of minutes until automatic refresh of autoconfig URL by autodiscovery. [CorrespondingType(typeof(string), CorrespondingAction.GetSet)] INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS = 7, /// Read only option. Returns the time the last known good autoconfig URL was found using autodiscovery. [CorrespondingType(typeof(FILETIME), CorrespondingAction.Get)] INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME = 8, /// Read only option. Returns the last known good URL found using autodiscovery. [CorrespondingType(typeof(string), CorrespondingAction.Get)] INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL = 9, /// Sets or retrieves the connection type. [CorrespondingType(typeof(uint), CorrespondingAction.GetSet)] INTERNET_PER_CONN_FLAGS_UI = 10 } /// Transmission Control Protocol/Internet Protocol (TCP/IP) port on the server. [PInvokeData("wininet.h", MSDNShortId = "42b5d733-dccd-4c9d-8820-e358e033077c")] public enum INTERNET_PORT : ushort { /// Uses the default port for the service specified by dwService. INTERNET_INVALID_PORT_NUMBER = 0, /// Uses the default port for FTP servers (port 21). INTERNET_DEFAULT_FTP_PORT = 21, /// Uses the default port for Gopher servers (port 70). INTERNET_DEFAULT_GOPHER_PORT = 70, /// Uses the default port for HTTP servers (port 80). INTERNET_DEFAULT_HTTP_PORT = 80, /// Uses the default port for Secure Hypertext Transfer Protocol (HTTPS) servers (port 443). INTERNET_DEFAULT_HTTPS_PORT = 443, /// Uses the default port for SOCKS firewall servers (port 1080). INTERNET_DEFAULT_SOCKS_PORT = 1080, } /// RFC formats. [PInvokeData("wininet.h", MSDNShortId = "b52ba402-bad1-4005-b9d0-7630194272d1")] public enum INTERNET_RFC { /// RFC 1123 format. INTERNET_RFC1123_FORMAT = 0 } /// Defines the flags used with the nScheme member of the URL_COMPONENTS structure. /// /// Note WinINet does not support server implementations. In addition, it should not be used from a service. For server /// implementations or services use Microsoft Windows HTTP Services (WinHTTP). /// // https://docs.microsoft.com/en-us/windows/win32/api/wininet/ne-wininet-internet_scheme typedef enum { INTERNET_SCHEME_PARTIAL, // INTERNET_SCHEME_UNKNOWN, INTERNET_SCHEME_DEFAULT, INTERNET_SCHEME_FTP, INTERNET_SCHEME_GOPHER, INTERNET_SCHEME_HTTP, // INTERNET_SCHEME_HTTPS, INTERNET_SCHEME_FILE, INTERNET_SCHEME_NEWS, INTERNET_SCHEME_MAILTO, INTERNET_SCHEME_SOCKS, // INTERNET_SCHEME_JAVASCRIPT, INTERNET_SCHEME_VBSCRIPT, INTERNET_SCHEME_RES, INTERNET_SCHEME_FIRST, INTERNET_SCHEME_LAST } *LPINTERNET_SCHEME; [PInvokeData("wininet.h", MSDNShortId = "640d0b62-a44f-4115-be27-9976da4bc73a")] public enum INTERNET_SCHEME { /// Partial URL. INTERNET_SCHEME_PARTIAL = -2, /// Unknown URL scheme. INTERNET_SCHEME_UNKNOWN = -1, /// Default URL scheme. INTERNET_SCHEME_DEFAULT = 0, /// FTP URL scheme (ftp:). INTERNET_SCHEME_FTP, /// Gopher URL scheme (gopher:). INTERNET_SCHEME_GOPHER, /// HTTP URL scheme (http:). INTERNET_SCHEME_HTTP, /// HTTPS URL scheme (https:). INTERNET_SCHEME_HTTPS, /// File URL scheme (file:). INTERNET_SCHEME_FILE, /// News URL scheme (news:). INTERNET_SCHEME_NEWS, /// Mail URL scheme (mailto:). INTERNET_SCHEME_MAILTO, /// Socks URL scheme (socks:). INTERNET_SCHEME_SOCKS, /// JScript URL scheme (javascript:). INTERNET_SCHEME_JAVASCRIPT, /// VBScript URL scheme (vbscript:). INTERNET_SCHEME_VBSCRIPT, /// Resource URL scheme (res:). INTERNET_SCHEME_RES, /// Lowest known scheme value. INTERNET_SCHEME_FIRST = INTERNET_SCHEME_FTP, /// Highest known scheme value. INTERNET_SCHEME_LAST = INTERNET_SCHEME_RES, } /// Options for the function. [PInvokeData("WinInet.h")] [Flags] public enum InternetApiFlags : uint { /// Indicates that a Platform for Privacy Protection (P3P) header is to be associated with a cookie. INTERNET_COOKIE_EVALUATE_P3P = 0x80, /// Indicates that a third-party cookie is being set or retrieved. INTERNET_COOKIE_THIRD_PARTY = 0x10, /// /// Makes only asynchronous requests on handles descended from the handle returned from this function. Only the InternetOpen /// function uses this flag. /// INTERNET_FLAG_ASYNC = 0x10000000, /// Allows a lazy cache write. INTERNET_FLAG_CACHE_ASYNC = 0x00000080, /// /// Returns the resource from the cache if the network request for the resource fails due to an ERROR_INTERNET_CONNECTION_RESET /// or ERROR_INTERNET_CANNOT_CONNECT error. This flag is used by HttpOpenRequest. /// INTERNET_FLAG_CACHE_IF_NET_FAIL = 0x00010000, /// Does not add the returned entity to the cache. This is identical to the preferred value, INTERNET_FLAG_NO_CACHE_WRITE. INTERNET_FLAG_DONT_CACHE = 0x04000000, /// /// Attempts to use an existing InternetConnect object if one exists with the same attributes required to make the request. This /// is useful only with FTP operations, since FTP is the only protocol that typically performs multiple operations during the /// same session. WinINet caches a single connection handle for each HINTERNET handle generated by InternetOpen. The /// InternetOpenUrl and InternetConnect functions use this flag for Http and Ftp connections. /// INTERNET_FLAG_EXISTING_CONNECT = 0x20000000, /// Indicates that this is a Forms submission. INTERNET_FLAG_FORMS_SUBMIT = 0x00000040, /// /// Does not make network requests. All entities are returned from the cache. If the requested item is not in the cache, a /// suitable error, such as ERROR_FILE_NOT_FOUND, is returned. Only the InternetOpen function uses this flag. /// INTERNET_FLAG_FROM_CACHE = 0x01000000, /// /// Indicates that the function should use the copy of the resource that is currently in the Internet cache. The expiration date /// and other information about the resource is not checked. If the requested item is not found in the Internet cache, the /// system attempts to locate the resource on the network. This value was introduced in Microsoft Internet Explorer 5 and is /// associated with the Forward and Back button operations of Internet Explorer. /// INTERNET_FLAG_FWD_BACK = 0x00000020, /// /// Forces a reload if there is no Expires time and no LastModified time returned from the server when determining whether to /// reload the item from the network. This flag can be used by FtpFindFirstFile, FtpGetFile, FtpOpenFile, FtpPutFile, /// HttpOpenRequest, and InternetOpenUrl. /// Windows XP and Windows Server 2003 R2 and earlier: Also used by GopherFindFirstFile and GopherOpenFile. /// INTERNET_FLAG_HYPERLINK = 0x00000400, /// /// Disables checking of SSL/PCT-based certificates that are returned from the server against the host name given in the /// request. WinINet uses a simple check against certificates by comparing for matching host names and simple wildcarding rules. /// This flag can be used by HttpOpenRequest and InternetOpenUrl (for HTTP requests). /// INTERNET_FLAG_IGNORE_CERT_CN_INVALID = 0x00001000, /// /// Disables checking of SSL/PCT-based certificates for proper validity dates. This flag can be used by HttpOpenRequest and /// InternetOpenUrl (for HTTP requests). /// INTERNET_FLAG_IGNORE_CERT_DATE_INVALID = 0x00002000, /// /// Disables detection of this special type of redirect. When this flag is used, WinINet transparently allows redirects from /// HTTPS to HTTP URLs. This flag can be used by HttpOpenRequest and InternetOpenUrl (for HTTP requests). /// INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTP = 0x00008000, /// /// Disables detection of this special type of redirect. When this flag is used, WinINet transparently allow redirects from HTTP /// to HTTPS URLs. This flag can be used by HttpOpenRequest and InternetOpenUrl (for HTTP requests). /// INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTPS = 0x00004000, /// /// Uses keep-alive semantics, if available, for the connection. This flag is used by HttpOpenRequest and InternetOpenUrl (for /// HTTP requests). This flag is required for Microsoft Network (MSN), NTLM, and other types of authentication. /// INTERNET_FLAG_KEEP_CONNECTION = 0x00400000, /// No longer supported. INTERNET_FLAG_MAKE_PERSISTENT = 0x02000000, /// /// Identical to the preferred value, INTERNET_FLAG_NEED_FILE. Causes a temporary file to be created if the file cannot be /// cached. This flag can be used by FtpFindFirstFile, FtpGetFile, FtpOpenFile, FtpPutFile, HttpOpenRequest, and InternetOpenUrl. /// Windows XP and Windows Server 2003 R2 and earlier: Also used by GopherFindFirstFile and GopherOpenFile. /// INTERNET_FLAG_MUST_CACHE_REQUEST = 0x00000010, /// /// Causes a temporary file to be created if the file cannot be cached. This flag can be used by FtpFindFirstFile, FtpGetFile, /// FtpOpenFile, FtpPutFile, HttpOpenRequest, and InternetOpenUrl. /// Windows XP and Windows Server 2003 R2 and earlier: Also used by GopherFindFirstFile and GopherOpenFile. /// INTERNET_FLAG_NEED_FILE = 0x00000010, /// /// Does not attempt authentication automatically. This flag can be used by HttpOpenRequest and InternetOpenUrl (for HTTP requests). /// INTERNET_FLAG_NO_AUTH = 0x00040000, /// /// Does not automatically handle redirection in HttpSendRequest. This flag can also be used by InternetOpenUrl for HTTP requests. /// INTERNET_FLAG_NO_AUTO_REDIRECT = 0x00200000, /// /// Does not add the returned entity to the cache. This flag is used by , HttpOpenRequest, and InternetOpenUrl. /// Windows XP and Windows Server 2003 R2 and earlier: Also used by GopherFindFirstFile and GopherOpenFile. /// INTERNET_FLAG_NO_CACHE_WRITE = 0x04000000, /// /// Does not automatically add cookie headers to requests, and does not automatically add returned cookies to the cookie /// database. This flag can be used by HttpOpenRequest and InternetOpenUrl (for HTTP requests). /// INTERNET_FLAG_NO_COOKIES = 0x00080000, /// /// Disables the cookie dialog box. This flag can be used by HttpOpenRequest and InternetOpenUrl (HTTP requests only). /// INTERNET_FLAG_NO_UI = 0x00000200, /// /// Identical to INTERNET_FLAG_FROM_CACHE. Does not make network requests. All entities are returned from the cache. If the /// requested item is not in the cache, a suitable error, such as ERROR_FILE_NOT_FOUND, is returned. Only the InternetOpen /// function uses this flag. /// INTERNET_FLAG_OFFLINE = 0x01000000, /// /// Uses passive FTP semantics. Only InternetConnect and InternetOpenUrl use this flag. InternetConnect uses this flag for FTP /// requests, and InternetOpenUrl uses this flag for FTP files and directories. /// INTERNET_FLAG_PASSIVE = 0x08000000, /// /// Forces the request to be resolved by the origin server, even if a cached copy exists on the proxy. The InternetOpenUrl /// function (on HTTP and HTTPS requests only) and HttpOpenRequest function use this flag. /// INTERNET_FLAG_PRAGMA_NOCACHE = 0x00000100, /// /// Returns the data as a WIN32_FIND_DATA structure when retrieving FTP directory information. If this flag is not specified or /// if the call is made through a CERN proxy, InternetOpenUrl returns the HTML version of the directory. Only the /// InternetOpenUrl function uses this flag. /// /// Windows XP and Windows Server 2003 R2 and earlier: Also returns a GOPHER_FIND_DATA structure when retrieving Gopher /// directory information. /// /// INTERNET_FLAG_RAW_DATA = 0x40000000, /// This flag is currently disabled. INTERNET_FLAG_READ_PREFETCH = 0x00100000, /// /// Forces a download of the requested file, object, or directory listing from the origin server, not from the cache. The /// FtpFindFirstFile, FtpGetFile, FtpOpenFile, FtpPutFile, HttpOpenRequest, and InternetOpenUrl functions use this flag. /// Windows XP and Windows Server 2003 R2 and earlier: Also used by GopherFindFirstFile and GopherOpenFile. /// INTERNET_FLAG_RELOAD = 0x80000000, /// Indicates that the cookie being set is associated with an untrusted site. INTERNET_FLAG_RESTRICTED_ZONE = 0x00020000, /// /// Reloads HTTP resources if the resource has been modified since the last time it was downloaded. All FTP resources are /// reloaded. This flag can be used by FtpFindFirstFile, FtpGetFile, FtpOpenFile, FtpPutFile, HttpOpenRequest, and InternetOpenUrl. /// /// Windows XP and Windows Server 2003 R2 and earlier: Also used by GopherFindFirstFile and GopherOpenFile, and Gopher resources /// are reloaded. /// /// INTERNET_FLAG_RESYNCHRONIZE = 0x00000800, /// /// Uses secure transaction semantics. This translates to using Secure Sockets Layer/Private Communications Technology (SSL/PCT) /// and is only meaningful in HTTP requests. This flag is used by HttpOpenRequest and InternetOpenUrl, but this is redundant if /// https:// appears in the URL.The InternetConnect function uses this flag for HTTP connections; all the request handles /// created under this connection will inherit this flag. /// INTERNET_FLAG_SECURE = 0x00800000, /// Transfers file as ASCII (FTP only). This flag can be used by FtpOpenFile, FtpGetFile, and FtpPutFile. INTERNET_FLAG_TRANSFER_ASCII = 0x00000001, /// Transfers file as binary (FTP only). This flag can be used by FtpOpenFile, FtpGetFile, and FtpPutFile. INTERNET_FLAG_TRANSFER_BINARY = 0x00000002, /// /// Indicates that no callbacks should be made for that API. This is used for the dxContext parameter of the functions that /// allow asynchronous operations. /// INTERNET_NO_CALLBACK = 0x00000000, /// /// Sets an HTTP request object such that it will not logon to origin servers, but will perform automatic logon to HTTP proxy /// servers. This option differs from the Request flag INTERNET_FLAG_NO_AUTH, which prevents authentication to both proxy /// servers and origin servers. Setting this mode will suppress the use of any credential material (either previously provided /// username/password or client SSL certificate) when communicating with an origin server. However, if the request must transit /// via an authenticating proxy, WinINet will still perform automatic authentication to the HTTP proxy per the Intranet Zone /// settings for the user. The default Intranet Zone setting is to permit automatic logon using the user’s default credentials. /// To ensure suppression of all identifying information, the caller should combine INTERNET_OPTION_SUPPRESS_SERVER_AUTH with /// the INTERNET_FLAG_NO_COOKIES request flag. This option may only be set on request objects before they have been sent. /// Attempts to set this option after the request has been sent will return ERROR_INTERNET_INCORRECT_HANDLE_STATE. No buffer is /// required for this option. This is used by InternetSetOption on handles returned by HttpOpenRequest only. Version: Requires /// Internet Explorer 8.0 or later. /// INTERNET_OPTION_SUPPRESS_SERVER_AUTH = 104, /// Forces asynchronous operations. WININET_API_FLAG_ASYNC = 0x00000001, /// Forces synchronous operations. WININET_API_FLAG_SYNC = 0x00000004, /// Forces the API to use the context value, even if it is set to zero. WININET_API_FLAG_USE_CONTEXT = 0x00000008 } /// The InternetCookieState enumeration defines the state of the cookie. /// /// Note WinINet does not support server implementations. In addition, it should not be used from a service. For server /// implementations or services use Microsoft Windows HTTP Services (WinHTTP). /// // https://docs.microsoft.com/en-us/windows/win32/api/wininet/ne-wininet-internetcookiestate typedef enum { COOKIE_STATE_UNKNOWN, // COOKIE_STATE_ACCEPT, COOKIE_STATE_PROMPT, COOKIE_STATE_LEASH, COOKIE_STATE_DOWNGRADE, COOKIE_STATE_REJECT, COOKIE_STATE_MAX } ; [PInvokeData("wininet.h", MSDNShortId = "3f43f492-3133-4cbd-9ab9-3c9600ef5263")] public enum InternetCookieState { /// Reserved. COOKIE_STATE_UNKNOWN, /// The cookies are accepted. COOKIE_STATE_ACCEPT, /// The user is prompted to accept or deny the cookie. COOKIE_STATE_PROMPT, /// Cookies are accepted only in the first-party context. COOKIE_STATE_LEASH, /// Cookies are accepted and become session cookies. COOKIE_STATE_DOWNGRADE, /// The cookies are rejected. COOKIE_STATE_REJECT, /// Same as COOKIE_STATE_REJECT. COOKIE_STATE_MAX, } /// Values available for the value. [PInvokeData("WinInet.h")] [Flags] public enum InternetErrorMask { /// The internet error mask insert cdrom INTERNET_ERROR_MASK_INSERT_CDROM = 0x1, /// The internet error mask combined sec cert INTERNET_ERROR_MASK_COMBINED_SEC_CERT = 0x2, /// The internet error mask need MSN sspi PKG INTERNET_ERROR_MASK_NEED_MSN_SSPI_PKG = 0X4, /// The internet error mask login failure display entity body INTERNET_ERROR_MASK_LOGIN_FAILURE_DISPLAY_ENTITY_BODY = 0x8, } /// /// Type of access required for the function. /// [PInvokeData("WinInet.h")] public enum InternetOpenType { /// Resolves all host names locally. INTERNET_OPEN_TYPE_DIRECT = 1, /// Retrieves the proxy or direct configuration from the registry. INTERNET_OPEN_TYPE_PRECONFIG = 0, /// /// Retrieves the proxy or direct configuration from the registry and prevents the use of a startup Microsoft JScript or /// Internet Setup (INS) file. /// INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY = 4, /// /// Passes requests to the proxy unless a proxy bypass list is supplied and the name to be resolved bypasses the proxy. In this /// case, the function uses INTERNET_OPEN_TYPE_DIRECT. /// INTERNET_OPEN_TYPE_PROXY = 3 } /// Error masks for internet functions. [PInvokeData("WinInet.h")] [Flags] public enum InternetOptionErrorMask { /// Indicates that the client application can handle the ERROR_INTERNET_INSERT_CDROM error code. INTERNET_ERROR_MASK_INSERT_CDROM = 0x1, /// /// Indicates that all certificate errors are to be reported using the same error return, namely ERROR_INTERNET_SEC_CERT_ERRORS. /// If this flag is set, call InternetErrorDlg upon receiving the ERROR_INTERNET_SEC_CERT_ERRORS error, so that the user can /// respond to a familiar dialog describing the problem. Caution Failing to inform the user of this error exposes the user to /// potential spoofing attacks. /// INTERNET_ERROR_MASK_COMBINED_SEC_CERT = 0x2, /// /// Indicates that the client application can handle the ERROR_INTERNET_LOGIN_FAILURE_DISPLAY_ENTITY_BODY error code. /// INTERNET_ERROR_MASK_LOGIN_FAILURE_DISPLAY_ENTITY_BODY = 0x8, /// Not implemented. INTERNET_ERROR_MASK_NEED_MSN_SSPI_PKG = 0x4, } /// The following option flags are used with the InternetQueryOption and InternetSetOption functions. [PInvokeData("WinInet.h")] [Flags] public enum InternetOptionFlags : uint { /// Not implemented [CorrespondingType(CorrespondingAction.Exception)] INTERNET_OPTION_ALTER_IDENTITY = 80, /// Not implemented. [CorrespondingType(CorrespondingAction.Exception)] INTERNET_OPTION_ASYNC = 30, /// Not implemented. [CorrespondingType(CorrespondingAction.Exception)] INTERNET_OPTION_ASYNC_ID = 15, /// Not implemented. [CorrespondingType(CorrespondingAction.Exception)] INTERNET_OPTION_ASYNC_PRIORITY = 16, /// /// Sets or retrieves the Boolean value that determines if the system should check the network for newer content and overwrite /// edited cache entries if a newer version is found. If set to True, the system checks the network for newer content and /// overwrites the edited cache entry with the newer version. The default is False, which indicates that the edited cache entry /// should be used without checking the network. This is used by InternetQueryOption and InternetSetOption. It is valid only in /// Microsoft Internet Explorer 5 and later. /// [CorrespondingType(typeof(bool))] INTERNET_OPTION_BYPASS_EDITED_ENTRY = 64, /// No longer supported. [CorrespondingType(CorrespondingAction.Exception)] INTERNET_OPTION_CACHE_STREAM_HANDLE = 27, /// /// Retrieves an INTERNET_CACHE_TIMESTAMPS structure that contains the LastModified time and Expires time from the resource /// stored in the Internet cache. This value is used by InternetQueryOption. /// [CorrespondingType(typeof(INTERNET_CACHE_TIMESTAMPS), CorrespondingAction.Get)] INTERNET_OPTION_CACHE_TIMESTAMPS = 69, /// /// Sets or retrieves the address of the callback function defined for this handle. This option can be used on all HINTERNET /// handles. Used by InternetQueryOption and InternetSetOption. /// [CorrespondingType(typeof(InternetStatusCallback))] INTERNET_OPTION_CALLBACK = 1, /// Not implemented. [CorrespondingType(CorrespondingAction.Exception)] INTERNET_OPTION_CALLBACK_FILTER = 54, /// /// This flag is not supported by InternetQueryOption. The lpBuffer parameter must be a pointer to a CERT_CONTEXT structure and /// not a pointer to a CERT_CONTEXT pointer. If an application receives ERROR_INTERNET_CLIENT_AUTH_CERT_NEEDED, it must call /// InternetErrorDlg or use InternetSetOption to supply a certificate before retrying the request. /// CertDuplicateCertificateContext is then called so that the certificate context passed can be independently released by the application. /// [CorrespondingType(typeof(IntPtr), CorrespondingAction.Set)] INTERNET_OPTION_CLIENT_CERT_CONTEXT = 84, /// /// For a request where WinInet decompressed the server’s supplied Content-Encoding, retrieves the server-reported /// Content-Length of the response body as a ULONGLONG. Supported in Windows 10, version 1507 and later. /// [CorrespondingType(typeof(ulong), CorrespondingAction.Get)] INTERNET_OPTION_COMPRESSED_CONTENT_LENGTH = 147, /// Not implemented. [CorrespondingType(CorrespondingAction.Exception)] INTERNET_OPTION_CONNECT_BACKOFF = 4, /// /// Sets or retrieves an unsigned long integer value that contains the number of times WinINet attempts to resolve and connect /// to a host. It only attempts once per IP address. For example, if you attempt to connect to a multihome host that has ten IP /// addresses and INTERNET_OPTION_CONNECT_RETRIES is set to seven, WinINet only attempts to resolve and connect to the first /// seven IP addresses. Conversely, given the same set of ten IP addresses, if INTERNET_OPTION_CONNECT_RETRIES is set to 20, /// WinINet attempts each of the ten only once. If a host has only one IP address and the first connection attempt fails, there /// are no further attempts. If a connection attempt still fails after the specified number of attempts, the request is /// canceled. The default value for INTERNET_OPTION_CONNECT_RETRIES is five attempts. This option can be used on any HINTERNET /// handle, including a NULL handle. It is used by InternetQueryOption and InternetSetOption. /// [CorrespondingType(typeof(uint))] INTERNET_OPTION_CONNECT_RETRIES = 3, /// Not implemented. [CorrespondingType(CorrespondingAction.Exception)] INTERNET_OPTION_CONNECT_TIME = 55, /// /// Sets or retrieves an unsigned long integer value that contains the connected state. This is used by InternetQueryOption and InternetSetOption. /// [CorrespondingType(typeof(uint))] INTERNET_OPTION_CONNECTED_STATE = 50, /// /// Sets or retrieves a DWORD_PTR that contains the address of the context value associated with this HINTERNET handle. This /// option can be used on any HINTERNET handle. This is used by InternetQueryOption and InternetSetOption. Previously, this set /// the context value to the address stored in the lpBuffer pointer. This has been corrected so that the value stored in the /// buffer is used and the INTERNET_OPTION_CONTEXT_VALUE flag is assigned a new value. The old value, 10, has been preserved so /// that applications written for the old behavior are still supported. /// [CorrespondingType(typeof(IntPtr))] INTERNET_OPTION_CONTEXT_VALUE = 45, /// Identical to INTERNET_OPTION_RECEIVE_TIMEOUT. This is used by InternetQueryOption and InternetSetOption. [CorrespondingType(typeof(uint))] INTERNET_OPTION_CONTROL_RECEIVE_TIMEOUT = 6, /// Identical to INTERNET_OPTION_SEND_TIMEOUT. This is used by InternetQueryOption and InternetSetOption. [CorrespondingType(typeof(uint))] INTERNET_OPTION_CONTROL_SEND_TIMEOUT = 5, /// /// Retrieves a string value that contains the name of the file backing a downloaded entity. This flag is valid after /// InternetOpenUrl, FtpOpenFile, GopherOpenFile, or HttpOpenRequest has completed. This option can only be queried by InternetQueryOption. /// [CorrespondingType(typeof(string), CorrespondingAction.Get)] INTERNET_OPTION_DATAFILE_NAME = 33, /// /// Sets a string value that contains the extension of the file backing a downloaded entity. This flag should be set before /// calling InternetOpenUrl, FtpOpenFile, GopherOpenFile, or HttpOpenRequest. This option can only be set by InternetSetOption. /// [CorrespondingType(typeof(string), CorrespondingAction.Set)] INTERNET_OPTION_DATAFILE_EXT = 96, /// /// Causes the system to log off the Digest authentication SSPI package, purging all of the credentials created for the process. /// No buffer is required for this option. It is used by InternetSetOption. /// [CorrespondingType(null, CorrespondingAction.Set)] INTERNET_OPTION_DIGEST_AUTH_UNLOAD = 76, /// Not implemented. [CorrespondingType(CorrespondingAction.Exception)] INTERNET_OPTION_DISABLE_AUTODIAL = 70, /// Not implemented. [CorrespondingType(CorrespondingAction.Exception)] INTERNET_OPTION_DISCONNECTED_TIMEOUT = 49, /// /// On a request handle, sets a Boolean controlling whether redirects will be returned from the WinInet cache for a given /// request. The default is FALSE. Supported in Windows 8 and later. /// [CorrespondingType(typeof(bool), CorrespondingAction.Set)] INTERNET_OPTION_ENABLE_REDIRECT_CACHE_READ = 122, /// /// Gets/sets a BOOL indicating whether non-ASCII characters in the query string should be percent-encoded. The default is /// FALSE. Supported in Windows 8.1 and later. /// [CorrespondingType(typeof(bool))] INTERNET_OPTION_ENCODE_EXTRA = 155, /// /// Flushes entries not in use from the password cache on the hard disk drive. Also resets the cache time used when the /// synchronization mode is once-per-session. No buffer is required for this option. This is used by InternetSetOption. /// [CorrespondingType(null, CorrespondingAction.Set)] INTERNET_OPTION_END_BROWSER_SESSION = 42, /// Sets an unsigned long integer value that contains the error masks that can be handled by the client application. [CorrespondingType(typeof(InternetErrorMask), CorrespondingAction.Set)] INTERNET_OPTION_ERROR_MASK = 62, /// /// Sets a PWSTR containing the Enterprise ID (see /// https://msdn.microsoft.com/en-us/library/windows/desktop/mt759320(v=vs.85).aspx) which applies to the request. Supported in /// Windows 10, version 1507 and later. /// [CorrespondingType(typeof(InternetErrorMask), CorrespondingAction.Set)] INTERNET_OPTION_ENTERPRISE_CONTEXT = 159, /// /// Retrieves an unsigned long integer value that contains a Winsock error code mapped to the ERROR_INTERNET_ error messages /// last returned in this thread context. This option is used on a NULLHINTERNET handle by InternetQueryOption. /// [CorrespondingType(typeof(uint), CorrespondingAction.Get)] INTERNET_OPTION_EXTENDED_ERROR = 24, /// /// Sets or retrieves a1n unsigned long integer value that contains the amount of time the system should wait for a response to /// a network request before checking the cache for a copy of the resource. If a network request takes longer than the time /// specified and the requested resource is available in the cache, the resource is retrieved from the cache. This is used by /// InternetQueryOption and InternetSetOption. /// [CorrespondingType(typeof(uint))] INTERNET_OPTION_FROM_CACHE_TIMEOUT = 63, /// /// Retrieves an unsigned long integer value that contains the type of the HINTERNET handles passed in. This is used by /// InternetQueryOption on any HINTERNET handle. Returns a InternetOptionHandleType value. /// [CorrespondingType(typeof(InternetOptionHandleType), CorrespondingAction.Get)] INTERNET_OPTION_HANDLE_TYPE = 9, /// /// Gets/sets a BOOL indicating whether WinInet should follow HTTP Strict Transport Security (HSTS) directives from servers. If /// enabled, http:// schemed requests to domains which have an HSTS policy cached by WinInet will be redirected to matching /// https:// URLs. The default is FALSE. Supported in Windows 8.1 and later. /// [CorrespondingType(typeof(bool))] INTERNET_OPTION_HSTS = 157, /// /// Enables WinINet to perform decoding for the gzip and deflate encoding schemes. For more information, see Content Encoding. /// [CorrespondingType(typeof(bool), CorrespondingAction.Set)] INTERNET_OPTION_HTTP_DECODING = 65, /// Not implemented. [CorrespondingType(CorrespondingAction.Exception)] INTERNET_OPTION_IDENTITY = 78, /// Not implemented. [CorrespondingType(CorrespondingAction.Exception)] INTERNET_OPTION_IDLE_STATE = 51, /// /// Sets or retrieves whether the global offline flag should be ignored for the specified request handle. No buffer is required /// for this option. This is used by InternetQueryOption and InternetSetOption with a request handle. This option is only valid /// in Internet Explorer 5 and later. /// [CorrespondingType(null)] INTERNET_OPTION_IGNORE_OFFLINE = 77, /// Not implemented. [CorrespondingType(CorrespondingAction.Exception)] INTERNET_OPTION_KEEP_CONNECTION = 22, /// Not implemented. [CorrespondingType(CorrespondingAction.Exception)] INTERNET_OPTION_LISTEN_TIMEOUT = 11, /// /// Sets or retrieves an unsigned long integer value that contains the maximum number of connections allowed per HTTP/1.0 /// server. This is used by InternetQueryOption and InternetSetOption. This option is only valid in Internet Explorer 5 and later. /// [CorrespondingType(typeof(uint))] INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER = 74, /// /// Sets or retrieves an unsigned long integer value that contains the maximum number of connections allowed per server. This is /// used by InternetQueryOption and InternetSetOption. This option is only valid in Internet Explorer 5 and later. /// [CorrespondingType(typeof(uint))] INTERNET_OPTION_MAX_CONNS_PER_SERVER = 73, /// Not implemented. [CorrespondingType(CorrespondingAction.Exception)] INTERNET_OPTION_OFFLINE_MODE = 26, /// Not implemented. [CorrespondingType(CorrespondingAction.Exception)] INTERNET_OPTION_OFFLINE_SEMANTICS = 52, /// /// Opt-in for weak signatures (e.g. SHA-1) to be treated as insecure. This will instruct WinInet to call /// CertGetCertificateChain using the CERT_CHAIN_OPT_IN_WEAK_SIGNATURE parameter. /// [CorrespondingType(typeof(bool))] INTERNET_OPTION_OPT_IN_WEAK_SIGNATURE = 176, /// Retrieves the parent handle to this handle. This option can be used on any HINTERNET handle by InternetQueryOption. [CorrespondingType(typeof(IntPtr), CorrespondingAction.Get)] INTERNET_OPTION_PARENT_HANDLE = 21, /// /// Sets or retrieves a string value that contains the password associated with a handle returned by InternetConnect. This is /// used by InternetQueryOption and InternetSetOption. /// [CorrespondingType(typeof(string))] INTERNET_OPTION_PASSWORD = 29, /// Not implemented. [CorrespondingType(CorrespondingAction.Exception)] INTERNET_OPTION_POLICY = 48, /// /// Sets or retrieves a string value that contains the password used to access the proxy. This is used by InternetQueryOption /// and InternetSetOption. This option can be set on the handle returned by InternetConnect or HttpOpenRequest. /// [CorrespondingType(typeof(string))] INTERNET_OPTION_PROXY_PASSWORD = 44, /// /// Alerts the current WinInet instance that proxy settings have changed and that they must update with the new settings. To /// alert all available WinInet instances, set the Buffer parameter of InternetSetOption to NULL and BufferLength to 0 when /// passing this option. This option can be set on the handle returned by InternetConnect or HttpOpenRequest. /// [CorrespondingType(null, CorrespondingAction.Set)] INTERNET_OPTION_PROXY_SETTINGS_CHANGED = 95, /// /// Sets or retrieves a string value that contains the user name used to access the proxy. This is used by InternetQueryOption /// and InternetSetOption. This option can be set on the handle returned by InternetConnect or HttpOpenRequest. /// [CorrespondingType(typeof(string))] INTERNET_OPTION_PROXY_USERNAME = 43, /// /// Sets or retrieves an unsigned long integer value that contains the size of the read buffer. This option can be used on /// HINTERNET handles returned by FtpOpenFile, FtpFindFirstFile, and InternetConnect (FTP session only). This option is used by /// InternetQueryOption and InternetSetOption. /// [CorrespondingType(typeof(uint))] INTERNET_OPTION_READ_BUFFER_SIZE = 12, /// Not implemented. [CorrespondingType(CorrespondingAction.Exception)] INTERNET_OPTION_RECEIVE_THROUGHPUT = 57, /// /// Causes the proxy data to be reread from the registry for a handle. No buffer is required. This option can be used on the /// HINTERNET handle returned by InternetOpen. It is used by InternetSetOption. /// [CorrespondingType(null, CorrespondingAction.Set)] INTERNET_OPTION_REFRESH = 37, /// Not implemented. [CorrespondingType(CorrespondingAction.Exception)] INTERNET_OPTION_REMOVE_IDENTITY = 79, /// /// Retrieves an unsigned long integer value that contains the special status flags that indicate the status of the download in /// progress. This is used by InternetQueryOption. /// [CorrespondingType(typeof(InternetOptionRequestFlags), CorrespondingAction.Get)] INTERNET_OPTION_REQUEST_FLAGS = 23, /// /// Sets or retrieves an unsigned long integer value that contains the priority of requests that compete for a connection on an /// HTTP handle. This is used by InternetQueryOption and InternetSetOption. /// [CorrespondingType(typeof(uint))] INTERNET_OPTION_REQUEST_PRIORITY = 58, /// /// Starts a new cache session for the process. No buffer is required. This is used by InternetSetOption. This option is /// reserved for internal use only. /// [CorrespondingType(null, CorrespondingAction.Set)] INTERNET_OPTION_RESET_URLCACHE_SESSION = 60, /// /// Sets or retrieves a string value that contains the secondary cache key. This is used by InternetQueryOption and /// InternetSetOption. This option is reserved for internal use only. /// [CorrespondingType(typeof(string))] INTERNET_OPTION_SECONDARY_CACHE_KEY = 53, /// /// Retrieves the certificate for an SSL/PCT (Secure Sockets Layer/Private Communications Technology) server into a formatted /// string. This is used by InternetQueryOption. /// [CorrespondingType(typeof(string), CorrespondingAction.Get)] INTERNET_OPTION_SECURITY_CERTIFICATE = 35, /// /// Retrieves the certificate for an SSL/PCT server into the INTERNET_CERTIFICATE_INFO structure. This is used by InternetQueryOption. /// [CorrespondingType(typeof(INTERNET_CERTIFICATE_INFO), CorrespondingAction.Get)] INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT = 32, /// /// Retrieves an unsigned long integer value that contains the security flags for a handle. This option is used by /// InternetQueryOption. It can be a combination of the following values. /// [CorrespondingType(typeof(InternetOptionSecurityFlags), CorrespondingAction.Get)] INTERNET_OPTION_SECURITY_FLAGS = 31, /// /// Retrieves an unsigned long integer value that contains the bit size of the encryption key. The larger the number, the /// greater the encryption strength used. This is used by InternetQueryOption. Be aware that the data retrieved this way relates /// to a transaction that has already occurred, whose security level can no longer be changed. /// [CorrespondingType(typeof(uint), CorrespondingAction.Get)] INTERNET_OPTION_SECURITY_KEY_BITNESS = 36, /// Not implemented. [CorrespondingType(CorrespondingAction.Exception)] INTERNET_OPTION_SEND_THROUGHPUT = 56, /// /// Notifies the system that the registry settings have been changed so that it verifies the settings on the next call to /// InternetConnect. This is used by InternetSetOption. /// [CorrespondingType(null, CorrespondingAction.Set)] INTERNET_OPTION_SETTINGS_CHANGED = 39, /// /// A general purpose option that is used to suppress behaviors on a process-wide basis. The lpBuffer parameter of the function /// must be a pointer to a DWORD containing the specific behavior to suppress. This option cannot be queried with /// InternetQueryOption. The permitted values are: /// [CorrespondingType(typeof(InternetOptionSupressBehavior), CorrespondingAction.Set)] INTERNET_OPTION_SUPPRESS_BEHAVIOR = 81, /// /// Retrieves a string value that contains the full URL of a downloaded resource. If the original URL contained any extra data, /// such as search strings or anchors, or if the call was redirected, the URL returned differs from the original. This option is /// valid on HINTERNET handles returned by InternetOpenUrl, FtpOpenFile, GopherOpenFile, or HttpOpenRequest. It is used by InternetQueryOption. /// [CorrespondingType(typeof(string), CorrespondingAction.Get)] INTERNET_OPTION_URL = 34, /// /// Sets or retrieves the user agent string on handles supplied by InternetOpen and used in subsequent HttpSendRequest /// functions, as long as it is not overridden by a header added by HttpAddRequestHeaders or HttpSendRequest. This is used by /// InternetQueryOption and InternetSetOption. /// [CorrespondingType(typeof(string))] INTERNET_OPTION_USER_AGENT = 41, /// /// Sets or retrieves a string that contains the user name associated with a handle returned by InternetConnect. This is used by /// InternetQueryOption and InternetSetOption. /// [CorrespondingType(typeof(string))] INTERNET_OPTION_USERNAME = 28, /// /// Retrieves an INTERNET_VERSION_INFO structure that contains the version number of WinInet.dll. This option can be used on a /// NULLHINTERNET handle by InternetQueryOption. /// [CorrespondingType(typeof(INTERNET_VERSION_INFO), CorrespondingAction.Get)] INTERNET_OPTION_VERSION = 40, /// /// Sets or retrieves an unsigned long integer value that contains the size, in bytes, of the write buffer. This option can be /// used on HINTERNET handles returned by FtpOpenFile and InternetConnect (FTP session only). It is used by InternetQueryOption /// and InternetSetOption. /// [CorrespondingType(typeof(uint))] INTERNET_OPTION_WRITE_BUFFER_SIZE = 13, /// /// By default, the host or authority portion of the Unicode URL is encoded according to the IDN specification. Setting this /// option on the request, or connection handle, when IDN is disabled, specifies a code page encoding scheme for the host /// portion of the URL. The lpBuffer parameter in the call to InternetSetOption contains the desired DBCS code page. If no code /// page is specified in lpBuffer, WinINet uses the default system code page (CP_ACP). Note: This option is ignored if IDN is /// not disabled. For more information about how to disable IDN, see the INTERNET_OPTION_IDN option. /// Windows XP with SP2 and Windows Server 2003 with SP1: This flag is not supported. /// Version: Requires Internet Explorer 7.0. /// [CorrespondingType(typeof(uint), CorrespondingAction.Set)] INTERNET_OPTION_CODEPAGE = 68, /// /// By default, the path portion of the URL is UTF8 encoded. The WinINet API performs escape character (%) encoding on the /// high-bit characters. Setting this option on the request, or connection handle, disables the UTF8 encoding and sets a /// specific code page. The lpBuffer parameter in the call to InternetSetOption contains the desired DBCS codepage for the path. /// If no code page is specified in lpBuffer, WinINet uses the default CP_UTF8. /// Windows XP with SP2 and Windows Server 2003 with SP1: This flag is not supported. /// Version: Requires Internet Explorer 7.0. /// [CorrespondingType(typeof(uint), CorrespondingAction.Set)] INTERNET_OPTION_CODEPAGE_PATH = 100, /// /// By default, the path portion of the URL is the default system code page (CP_ACP). The escape character (%) conversions are /// not performed on the extra portion. Setting this option on the request, or connection handle disables the CP_ACP encoding. /// The lpBuffer parameter in the call to InternetSetOption contains the desired DBCS codepage for the extra portion of the URL. /// If no code page is specified in lpBuffer, WinINet uses the default system code page (CP_ACP). /// Windows XP with SP2 and Windows Server 2003 with SP1: This flag is not supported. /// Version: Requires Internet Explorer 7.0. /// [CorrespondingType(typeof(uint), CorrespondingAction.Set)] INTERNET_OPTION_CODEPAGE_EXTRA = 101, /// /// Sets or retrieves an unsigned long integer value that contains the time-out value, in milliseconds, to use for Internet /// connection requests. Setting this option to infinite (0xFFFFFFFF) will disable this timer. If a connection request takes /// longer than this time-out value, the request is canceled. When attempting to connect to multiple IP addresses for a single /// host (a multihome host), the timeout limit is cumulative for all of the IP addresses. This option can be used on any /// HINTERNET handle, including a NULL handle. It is used by InternetQueryOption and InternetSetOption. /// [CorrespondingType(typeof(uint))] INTERNET_OPTION_CONNECT_TIMEOUT = 2, /// /// Sets or retrieves an unsigned long integer value that contains the time-out value, in milliseconds, to receive a response to /// a request for the data channel of an FTP transaction. If the response takes longer than this time-out value, the request is /// canceled. This option can be used on any HINTERNET handle, including a NULL handle. It is used by InternetQueryOption and /// InternetSetOption. This flag has no impact on HTTP functionality. /// [CorrespondingType(typeof(uint))] INTERNET_OPTION_DATA_RECEIVE_TIMEOUT = 8, /// /// Sets or retrieves an unsigned long integer value, in milliseconds, that contains the time-out value to send a request for /// the data channel of an FTP transaction. If the send takes longer than this time-out value, the send is canceled. This option /// can be used on any HINTERNET handle, including a NULL handle. It is used by InternetQueryOption and InternetSetOption. This /// flag has no impact on HTTP functionality. /// [CorrespondingType(typeof(uint))] INTERNET_OPTION_DATA_SEND_TIMEOUT = 7, /// /// Retrieves an INTERNET_DIAGNOSTIC_SOCKET_INFO structure that contains data about a specified HTTP Request. This flag is used /// by InternetQueryOption. Windows 7: This option is no longer supported. /// [CorrespondingType(typeof(INTERNET_DIAGNOSTIC_SOCKET_INFO), CorrespondingAction.Get)] INTERNET_OPTION_DIAGNOSTIC_SOCKET_INFO = 67, /// /// Sets a DWORD bitmask of acceptable advanced HTTP versions. May be set on any handle type. Possible values are: /// HTTP_PROTOCOL_FLAG_HTTP2 (0x2). Supported on Windows 10, version 1507 and later. Legacy versions of HTTP (1.1 and prior) /// cannot be disabled using this option. The default is 0x0. Supported in Windows 10, version 1507 and later. /// [CorrespondingType(typeof(uint), CorrespondingAction.Set)] INTERNET_OPTION_ENABLE_HTTP_PROTOCOL = 148, /// /// Gets a DWORD indicating which advanced HTTP version was used on a given request. Possible values are: /// HTTP_PROTOCOL_FLAG_HTTP2 (0x2). Supported on Windows 10, version 1507 and later. 0x0 indicates HTTP/1.1 or earlier; see /// INTERNET_OPTION_HTTP_VERSION if more precision is needed about which legacy version was used. Supported on Windows 10, /// version 1507 and later. /// [CorrespondingType(typeof(uint), CorrespondingAction.Get)] INTERNET_OPTION_HTTP_PROTOCOL_USED = 149, /// /// Sets or retrieves an HTTP_VERSION_INFO structure that contains the supported HTTP version. This must be used on a NULL /// handle. This is used by InternetQueryOption and InternetSetOption. On Windows 7, Windows Server 2008 R2, and later, the /// value of the dwMinorVersion member in the HTTP_VERSION_INFO structure is overridden by Internet Explorer settings. /// EnableHttp1_1 is a registry value under HKLM\Software\Microsoft\InternetExplorer\AdvacnedOptions\HTTP\GENABLE controlled by /// Internet Options set in Internet Explorer for the system. The EnableHttp1_1 value defaults to 1. The HTTP_VERSION_INFO /// structure is ignored for any HTTP version less than 1.1 if EnableHttp1_1 is set to 1. /// [CorrespondingType(typeof(INTERNET_VERSION_INFO))] INTERNET_OPTION_HTTP_VERSION = 59, /// /// By default, the host or authority portion of the URL is encoded according to the IDN specification for both direct and proxy /// connections. This option can be used on the request, or connection handle to enable or disable IDN. When IDN is disabled, /// WinINet uses the system codepage to encode the host or authority portion of the URL. To disable IDN host conversion, set the /// lpBuffer parameter in the call to InternetSetOption to zero. To enable IDN conversion on only the direct connection, specify /// INTERNET_FLAG_IDN_DIRECT in the lpBuffer parameter in the call to InternetSetOption. To enable IDN conversion on only the /// proxy connection, specify INTERNET_FLAG_IDN_PROXY in the lpBuffer parameter in the call to InternetSetOption. Windows XP /// with SP2 and Windows Server 2003 with SP1: This flag is not supported. /// Version: Requires Internet Explorer 7.0. /// [CorrespondingType(typeof(InternetOptionIDNFlags), CorrespondingAction.Set)] INTERNET_OPTION_IDN = 102, /// /// Sets or retrieves an unsigned long integer value that contains the maximum number of connections allowed per CERN proxy. /// When this option is set or retrieved, the hInternet parameter must set to a null handle value. A null handle value indicates /// that the option should be set or queried for the current process. When calling InternetSetOption with this option, all /// existing proxy objects will receive the new value. This value is limited to a range of 2 to 128, inclusive. Version: /// Requires Internet Explorer 8.0. /// [CorrespondingType(typeof(uint))] INTERNET_OPTION_MAX_CONNS_PER_PROXY = 103, /// /// Sets or retrieves an INTERNET_PER_CONN_OPTION_LIST structure that specifies a list of options for a particular connection. /// This is used by InternetQueryOption and InternetSetOption. This option is only valid in Internet Explorer 5 and later. Note /// INTERNET_OPTION_PER_CONNECTION_OPTION causes the settings to be changed on a system-wide basis when a NULL handle is used in /// the call to InternetSetOption. To refresh the global proxy settings, you must call InternetSetOption with the /// INTERNET_OPTION_REFRESH option flag. Note To change proxy information for the entire process without affecting the global /// settings in Internet Explorer 5 and later, use this option on the handle that is returned from InternetOpen. The following /// code example changes the proxy for the whole process even though the HINTERNET handle is closed and is not used by any /// requests. For more information and code examples, see KB article 226473. /// [CorrespondingType(typeof(INTERNET_PER_CONN_OPTION_LIST))] INTERNET_OPTION_PER_CONNECTION_OPTION = 75, /// /// Sets or retrieves an INTERNET_PROXY_INFO structure that contains the proxy data for an existing InternetOpen handle when the /// HINTERNET handle is not NULL. If the HINTERNET handle is NULL, the function sets or queries the global proxy data. This /// option can be used on the handle returned by InternetOpen. It is used by InternetQueryOption and InternetSetOption. Note It /// is recommended that INTERNET_OPTION_PER_CONNECTION_OPTION be used instead of INTERNET_OPTION_PROXY. For more information, /// see KB article 226473. /// [CorrespondingType(typeof(INTERNET_PROXY_INFO))] INTERNET_OPTION_PROXY = 38, /// /// Sets or retrieves an unsigned long integer value that contains the time-out value, in milliseconds, to receive a response to /// a request. If the response takes longer than this time-out value, the request is canceled. This option can be used on any /// HINTERNET handle, including a NULL handle. It is used by InternetQueryOption and InternetSetOption. This option is not /// intended to represent a fine-grained, immediate timeout. You can expect the timeout to occur up to six seconds after the set /// timeout value. When used in reference to an FTP transaction, this option refers to the control channel. /// [CorrespondingType(typeof(uint))] INTERNET_OPTION_RECEIVE_TIMEOUT = 6, /// /// The bit size used in the encryption is unknown. This is only returned in a call to InternetQueryOption. Be aware that the /// data retrieved this way relates to a transaction that has occurred, whose security level can no longer be changed. /// [CorrespondingType(typeof(uint), CorrespondingAction.Get)] SECURITY_FLAG_UNKNOWNBIT = 0x80000000, /// /// Sets or retrieves an unsigned long integer value, in milliseconds, that contains the time-out value to send a request. If /// the send takes longer than this time-out value, the send is canceled. This option can be used on any HINTERNET handle, /// including a NULL handle. It is used by InternetQueryOption and InternetSetOption. When used in reference to an FTP /// transaction, this option refers to the control channel. /// [CorrespondingType(typeof(uint))] INTERNET_OPTION_SEND_TIMEOUT = 5, /// /// Retrieves the server’s certificate-chain context as a duplicated PCCERT_CHAIN_CONTEXT. You may pass this duplicated context /// to any Crypto API function which takes a PCCERT_CHAIN_CONTEXT. You must call CertFreeCertificateChain on the returned /// PCCERT_CHAIN_CONTEXT when you are done with the certificate-chain context. Version: Requires Internet Explorer 8.0. /// [CorrespondingType(typeof(IntPtr), CorrespondingAction.Get)] INTERNET_OPTION_SERVER_CERT_CHAIN_CONTEXT = 105, /// /// Sets an HTTP request object such that it will not logon to origin servers, but will perform automatic logon to HTTP proxy /// servers. This option differs from the Request flag INTERNET_FLAG_NO_AUTH, which prevents authentication to both proxy /// servers and origin servers. Setting this mode will suppress the use of any credential material (either previously provided /// username/password or client SSL certificate) when communicating with an origin server. However, if the request must transit /// via an authenticating proxy, WinINet will still perform automatic authentication to the HTTP proxy per the Intranet Zone /// settings for the user. The default Intranet Zone setting is to permit automatic logon using the user’s default credentials. /// To ensure suppression of all identifying information, the caller should combine INTERNET_OPTION_SUPPRESS_SERVER_AUTH with /// the INTERNET_FLAG_NO_COOKIES request flag. This option may only be set on request objects before they have been sent. /// Attempts to set this option after the request has been sent will return ERROR_INTERNET_INCORRECT_HANDLE_STATE. No buffer is /// required for this option. This is used by InternetSetOption on handles returned by HttpOpenRequest only. /// Version: Requires Internet Explorer 8.0 or later. /// [CorrespondingType(null, CorrespondingAction.Set)] INTERNET_OPTION_SUPPRESS_SERVER_AUTH = 104, } /// Handle types. [PInvokeData("WinInet.h")] public enum InternetOptionHandleType { /// /// Retrieves an unsigned long integer value that contains the type of the HINTERNET handles passed in. This is used by /// InternetQueryOption on any HINTERNET handle. Possible return values include the following. /// INTERNET_HANDLE_TYPE_CONNECT_FTP = 2, /// /// Retrieves an unsigned long integer value that contains the type of the HINTERNET handles passed in. This is used by /// InternetQueryOption on any HINTERNET handle. Possible return values include the following. /// INTERNET_HANDLE_TYPE_CONNECT_GOPHER = 3, /// /// Retrieves an unsigned long integer value that contains the type of the HINTERNET handles passed in. This is used by /// InternetQueryOption on any HINTERNET handle. Possible return values include the following. /// INTERNET_HANDLE_TYPE_CONNECT_HTTP = 4, /// /// Retrieves an unsigned long integer value that contains the type of the HINTERNET handles passed in. This is used by /// InternetQueryOption on any HINTERNET handle. Possible return values include the following. /// INTERNET_HANDLE_TYPE_FILE_REQUEST = 14, /// /// Retrieves an unsigned long integer value that contains the type of the HINTERNET handles passed in. This is used by /// InternetQueryOption on any HINTERNET handle. Possible return values include the following. /// INTERNET_HANDLE_TYPE_FTP_FILE = 7, /// /// Retrieves an unsigned long integer value that contains the type of the HINTERNET handles passed in. This is used by /// InternetQueryOption on any HINTERNET handle. Possible return values include the following. /// INTERNET_HANDLE_TYPE_FTP_FILE_HTML = 8, /// /// Retrieves an unsigned long integer value that contains the type of the HINTERNET handles passed in. This is used by /// InternetQueryOption on any HINTERNET handle. Possible return values include the following. /// INTERNET_HANDLE_TYPE_FTP_FIND = 5, /// /// Retrieves an unsigned long integer value that contains the type of the HINTERNET handles passed in. This is used by /// InternetQueryOption on any HINTERNET handle. Possible return values include the following. /// INTERNET_HANDLE_TYPE_FTP_FIND_HTML = 6, /// /// Retrieves an unsigned long integer value that contains the type of the HINTERNET handles passed in. This is used by /// InternetQueryOption on any HINTERNET handle. Possible return values include the following. /// INTERNET_HANDLE_TYPE_GOPHER_FILE = 11, /// /// Retrieves an unsigned long integer value that contains the type of the HINTERNET handles passed in. This is used by /// InternetQueryOption on any HINTERNET handle. Possible return values include the following. /// INTERNET_HANDLE_TYPE_GOPHER_FILE_HTML = 12, /// /// Retrieves an unsigned long integer value that contains the type of the HINTERNET handles passed in. This is used by /// InternetQueryOption on any HINTERNET handle. Possible return values include the following. /// INTERNET_HANDLE_TYPE_GOPHER_FIND = 9, /// /// Retrieves an unsigned long integer value that contains the type of the HINTERNET handles passed in. This is used by /// InternetQueryOption on any HINTERNET handle. Possible return values include the following. /// INTERNET_HANDLE_TYPE_GOPHER_FIND_HTML = 10, /// /// Retrieves an unsigned long integer value that contains the type of the HINTERNET handles passed in. This is used by /// InternetQueryOption on any HINTERNET handle. Possible return values include the following. /// INTERNET_HANDLE_TYPE_HTTP_REQUEST = 13, /// /// Retrieves an unsigned long integer value that contains the type of the HINTERNET handles passed in. This is used by /// InternetQueryOption on any HINTERNET handle. Possible return values include the following. /// INTERNET_HANDLE_TYPE_INTERNET = 1, } /// IDN flags [PInvokeData("WinInet.h")] [Flags] public enum InternetOptionIDNFlags { /// IDN enabled for direct connections INTERNET_FLAG_IDN_DIRECT = 0x00000001, /// IDN enabled for proxy INTERNET_FLAG_IDN_PROXY = 0x00000002 } /// Request flags. [PInvokeData("WinInet.h")] [Flags] public enum InternetOptionRequestFlags { /// Not implemented. INTERNET_REQFLAG_ASYNC = 0x00000002, /// Internet request cannot be cached (an HTTPS request, for example). INTERNET_REQFLAG_CACHE_WRITE_DISABLED = 0x00000040, /// Response came from the cache. INTERNET_REQFLAG_FROM_CACHE = 0x00000001, /// Internet request timed out. INTERNET_REQFLAG_NET_TIMEOUT = 0x00000080, /// Original response contained no headers. INTERNET_REQFLAG_NO_HEADERS = 0x00000008, /// Not implemented. INTERNET_REQFLAG_PASSIVE = 0x00000010, /// Request was made through a proxy. INTERNET_REQFLAG_VIA_PROXY = 0x00000004, } /// Security flags. [PInvokeData("WinInet.h")] [Flags] public enum InternetOptionSecurityFlags { /// Identical to the preferred value SECURITY_FLAG_STRENGTH_STRONG. This is only returned in a call to InternetQueryOption. SECURITY_FLAG_128BIT = 0x20000000, /// Identical to the preferred value SECURITY_FLAG_STRENGTH_WEAK. This is only returned in a call to InternetQueryOption. SECURITY_FLAG_40BIT = 0x10000000, /// Identical to the preferred value SECURITY_FLAG_STRENGTH_MEDIUM. This is only returned in a call to InternetQueryOption. SECURITY_FLAG_56BIT = 0x40000000, /// Indicates Fortezza has been used to provide secrecy, authentication, and/or integrity for the specified connection. SECURITY_FLAG_FORTEZZA = 0x08000000, /// Not implemented. SECURITY_FLAG_IETFSSL4 = 0x00000020, /// Ignores the ERROR_INTERNET_SEC_CERT_CN_INVALID error message. SECURITY_FLAG_IGNORE_CERT_CN_INVALID = 0x00001000, /// Ignores the ERROR_INTERNET_SEC_CERT_DATE_INVALID error message. SECURITY_FLAG_IGNORE_CERT_DATE_INVALID = 0x00002000, /// Ignores the ERROR_INTERNET_HTTPS_TO_HTTP_ON_REDIR error message. SECURITY_FLAG_IGNORE_REDIRECT_TO_HTTP = 0x00008000, /// Ignores the ERROR_INTERNET_HTTP_TO_HTTPS_ON_REDIR error message. SECURITY_FLAG_IGNORE_REDIRECT_TO_HTTPS = 0x00004000, /// Ignores certificate revocation problems. SECURITY_FLAG_IGNORE_REVOCATION = 0x00000080, /// Ignores unknown certificate authority problems. SECURITY_FLAG_IGNORE_UNKNOWN_CA = 0x00000100, /// Ignores weak certificate signature problems. SECURITY_FLAG_IGNORE_WEAK_SIGNATURE = 0x00010000, /// Ignores incorrect usage problems. SECURITY_FLAG_IGNORE_WRONG_USAGE = 0x00000200, /// Identical to the value SECURITY_FLAG_STRENGTH_WEAK. This is only returned in a call to InternetQueryOption. SECURITY_FLAG_NORMALBITNESS = 0x10000000, /// Not implemented. SECURITY_FLAG_PCT = 0x00000008, /// Not implemented. SECURITY_FLAG_PCT4 = 0x00000010, /// Uses secure transfers. This is only returned in a call to InternetQueryOption. SECURITY_FLAG_SECURE = 0x00000001, /// Not implemented. SECURITY_FLAG_SSL = 0x00000002, /// Not implemented. SECURITY_FLAG_SSL3 = 0x00000004, /// Uses medium (56-bit) encryption. This is only returned in a call to InternetQueryOption. SECURITY_FLAG_STRENGTH_MEDIUM = 0x40000000, /// Uses strong (128-bit) encryption. This is only returned in a call to InternetQueryOption. SECURITY_FLAG_STRENGTH_STRONG = 0x20000000, /// Uses weak (40-bit) encryption. This is only returned in a call to InternetQueryOption. SECURITY_FLAG_STRENGTH_WEAK = 0x10000000, } /// Behavior suppression flags. [PInvokeData("WinInet.h")] public enum InternetOptionSupressBehavior { /// /// Disables all suppressions, re-enabling default and configured behavior. This option is the equivalent of setting /// INTERNET_SUPPRESS_COOKIE_POLICY_RESET and INTERNET_SUPPRESS_COOKIE_PERSIST_RESET individually. Version: Requires /// Internet Explorer 6.0 or later. /// INTERNET_SUPPRESS_RESET_ALL = 0, /// /// Ignores any configured cookie policies and allows cookies to be set. Version: Requires Internet Explorer 6.0 or later. /// INTERNET_SUPPRESS_COOKIE_POLICY = 1, /// /// Disables the INTERNET_SUPPRESS_COOKIE_POLICY suppression, permitting the evaluation of cookies according to the configured /// cookie policy. Version: Requires Internet Explorer 6.0 or later. /// INTERNET_SUPPRESS_COOKIE_POLICY_RESET = 2, /// /// Suppresses the persistence of cookies, even if the server has specified them as persistent. Version: Requires /// Internet Explorer 8.0 or later. /// INTERNET_SUPPRESS_COOKIE_PERSIST = 3, /// /// Disables the INTERNET_SUPPRESS_COOKIE_PERSIST suppression, re-enabling the persistence of cookies. Any previously suppressed /// cookies will not become persistent. Version: Requires Internet Explorer 8.0 or later. /// INTERNET_SUPPRESS_COOKIE_PERSIST_RESET = 4 } /// Type of service to access in . [PInvokeData("WinInet.h")] public enum InternetService { /// FTP service. INTERNET_SERVICE_FTP = 1, /// Gopher service. Windows XP and Windows Server 2003 R2 and earlier only. INTERNET_SERVICE_GOPHER = 2, /// HTTP service. INTERNET_SERVICE_HTTP = 3 } /// Values passed using the delegate. [PInvokeData("WinInet.h")] [Flags] public enum InternetState { /// Connected state. Mutually exclusive with disconnected state. INTERNET_STATE_CONNECTED = 1, /// Disconnected state. No network connection could be established. INTERNET_STATE_DISCONNECTED = 2, /// Disconnected by user request. INTERNET_STATE_DISCONNECTED_BY_USER = 0x10, /// No network requests are being made by Windows Internet. INTERNET_STATE_IDLE = 0x100, /// Network requests are being made by Windows Internet. INTERNET_STATE_BUSY = 0x200, } /// Values passed using the delegate. [PInvokeData("WinInet.h")] public enum InternetStatus { /// Closing the connection to the server. The lpvStatusInformation parameter is NULL. INTERNET_STATUS_CLOSING_CONNECTION = 50, /// Successfully connected to the socket address (SOCKADDR) pointed to by lpvStatusInformation. INTERNET_STATUS_CONNECTED_TO_SERVER = 21, /// Connecting to the socket address (SOCKADDR) pointed to by lpvStatusInformation. INTERNET_STATUS_CONNECTING_TO_SERVER = 20, /// Successfully closed the connection to the server. The lpvStatusInformation parameter is NULL. INTERNET_STATUS_CONNECTION_CLOSED = 51, /// /// Retrieving content from the cache. Contains data about past cookie events for the URL such as if cookies were accepted, /// rejected, downgraded, or leashed. The lpvStatusInformation parameter is a pointer to an InternetCookieHistory structure. /// INTERNET_STATUS_COOKIE_HISTORY = 327, /// /// Indicates the number of cookies that were accepted, rejected, downgraded (changed from persistent to session cookies), or /// leashed (will be sent out only in 1st party context). The lpvStatusInformation parameter is a DWORD with the number of /// cookies received. /// INTERNET_STATUS_COOKIE_RECEIVED = 321, /// /// Indicates the number of cookies that were either sent or suppressed, when a request is sent. The lpvStatusInformation /// parameter is a DWORD with the number of cookies sent or suppressed. /// INTERNET_STATUS_COOKIE_SENT = 320, /// Not implemented. INTERNET_STATUS_CTL_RESPONSE_RECEIVED = 42, /// Notifies the client application that a proxy has been detected. INTERNET_STATUS_DETECTING_PROXY = 80, /// /// This handle value has been terminated. pvStatusInformation contains the address of the handle being closed. The /// lpvStatusInformation parameter contains the address of the handle being closed. /// INTERNET_STATUS_HANDLE_CLOSING = 70, /// /// Used by InternetConnect to indicate it has created the new handle. This lets the application call InternetCloseHandle from /// another thread, if the connect is taking too long. The lpvStatusInformation parameter contains the address of an HINTERNET handle. /// INTERNET_STATUS_HANDLE_CREATED = 60, /// Received an intermediate (100 level) status code message from the server. INTERNET_STATUS_INTERMEDIATE_RESPONSE = 120, /// /// Successfully found the IP address of the name contained in lpvStatusInformation. The lpvStatusInformation parameter points /// to a PCTSTR containing the host name. /// INTERNET_STATUS_NAME_RESOLVED = 11, /// The response has a P3P header in it. INTERNET_STATUS_P3P_HEADER = 325, /// Not implemented. INTERNET_STATUS_P3P_POLICYREF = 326, /// Not implemented. INTERNET_STATUS_PREFETCH = 43, /// Not implemented. INTERNET_STATUS_PRIVACY_IMPACTED = 324, /// Waiting for the server to respond to a request. The lpvStatusInformation parameter is NULL. INTERNET_STATUS_RECEIVING_RESPONSE = 40, /// /// An HTTP request is about to automatically redirect the request. The lpvStatusInformation parameter points to the new URL. At /// this point, the application can read any data returned by the server with the redirect response and can query the response /// headers. It can also cancel the operation by closing the handle. This callback is not made if the original request specified INTERNET_FLAG_NO_AUTO_REDIRECT. /// INTERNET_STATUS_REDIRECT = 110, /// /// An asynchronous operation has been completed. The lpvStatusInformation parameter contains the address of an /// INTERNET_ASYNC_RESULT structure. /// INTERNET_STATUS_REQUEST_COMPLETE = 100, /// /// Successfully sent the information request to the server. The lpvStatusInformation parameter points to a DWORD value that /// contains the number of bytes sent. /// INTERNET_STATUS_REQUEST_SENT = 31, /// /// Looking up the IP address of the name contained in lpvStatusInformation. The lpvStatusInformation parameter points to a /// PCTSTR containing the host name. /// INTERNET_STATUS_RESOLVING_NAME = 10, /// Successfully received a response from the server. INTERNET_STATUS_RESPONSE_RECEIVED = 41, /// Sending the information request to the server. The lpvStatusInformation parameter is NULL. INTERNET_STATUS_SENDING_REQUEST = 30, /// /// Moved between a secure (HTTPS) and a nonsecure (HTTP) site. The user must be informed of this change; otherwise, the user is /// at risk of disclosing sensitive information involuntarily. When this flag is set, the lpvStatusInformation parameter points /// to a status DWORD that contains additional flags. /// INTERNET_STATUS_STATE_CHANGE = 200, /// The request requires user input to be completed. INTERNET_STATUS_USER_INPUT_REQUIRED = 140, } /// Flags for . [PInvokeData("wininet.h", MSDNShortId = "04e7bb7e-d925-41fd-8333-3cb443a04c5b")] public enum IRF : uint { /// Identical to WININET_API_FLAG_ASYNC. IRF_ASYNC = 0x01, /// Identical to WININET_API_FLAG_SYNC. IRF_SYNC = 0x04, /// Identical to WININET_API_FLAG_USE_CONTEXT. IRF_USE_CONTEXT = 0x08, /// /// Do not wait for data. If there is data available, the function returns either the amount of data requested or the amount of /// data available (whichever is smaller). /// IRF_NO_WAIT = 0x08, } /// Values for INTERNET_PER_CONN_AUTODISCOVERY_FLAGS. [PInvokeData("wininet.h", MSDNShortId = "NS:wininet.__unnamed_struct_3")] [Flags] public enum PER_CONN_AUTODISCOVERY_FLAGS : uint { /// The user has explicitly set the automatic detection. AUTO_PROXY_FLAG_USER_SET = 0x00000001, /// Always automatically detect settings. AUTO_PROXY_FLAG_ALWAYS_DETECT = 0x00000002, /// Automatic detection has been run at least once on this connection. AUTO_PROXY_FLAG_DETECTION_RUN = 0x00000004, /// /// The setting was migrated from a Microsoft Internet Explorer 4.0 installation, and automatic detection should be attempted once. /// AUTO_PROXY_FLAG_MIGRATED = 0x00000008, /// Do not allow the caching of the result of the automatic proxy configuration script. AUTO_PROXY_FLAG_DONT_CACHE_PROXY_RESULT = 0x00000010, /// /// Indicates that the cached results of the automatic proxy configuration script should be used, instead of actually running /// the script, unless the cached file has expired. /// AUTO_PROXY_FLAG_CACHE_INIT_RUN = 0x00000020, /// Not currently supported. AUTO_PROXY_FLAG_DETECTION_SUSPECT = 0x00000040, } /// Values for INTERNET_PER_CONN_FLAGS. [PInvokeData("wininet.h", MSDNShortId = "NS:wininet.__unnamed_struct_3")] [Flags] public enum PER_CONN_FLAGS : uint { /// The connection does not use a proxy server. PROXY_TYPE_DIRECT = 0x00000001, /// The connection uses an explicitly set proxy server. PROXY_TYPE_PROXY = 0x00000002, /// The connection downloads and processes an automatic configuration script at a specified URL. PROXY_TYPE_AUTO_PROXY_URL = 0x00000004, /// The connection automatically detects settings. PROXY_TYPE_AUTO_DETECT = 0x00000008, } /// Privacy template for a URLL zone and type. [PInvokeData("wininet.h")] public enum PrivacyTemplate { /// This is the same as Block All Cookies on the Privacy Preferences slider bar in Internet Options. PRIVACY_TEMPLATE_NO_COOKIES = 0, /// This is the same as High on the Privacy Preferences slider bar in Internet Options. PRIVACY_TEMPLATE_HIGH = 1, /// This is the same as Medium_High on the Privacy Preferences slider bar in Internet Options. PRIVACY_TEMPLATE_MEDIUM_HIGH = 2, /// This is the same as Medium on the Privacy Preferences slider bar in Internet Options. PRIVACY_TEMPLATE_MEDIUM = 3, /// This is the same as Low on the Privacy Preferences slider bar in Internet Options. PRIVACY_TEMPLATE_MEDIUM_LOW = 4, /// This is the same as Accept All Cookies on the Privacy Preferences slider bar in Internet Options. PRIVACY_TEMPLATE_LOW = 5, /// User-defined. See How to Create a Customized Privacy Import File to understand how to set custom privacy settings. PRIVACY_TEMPLATE_CUSTOM = 100, /// /// User-defined. Advanced options are set in the Advanced Privacy Settings dialog reachable from the Privacy tab in Internet Options. /// PRIVACY_TEMPLATE_ADVANCED = 101, /// Same as PRIVACY_TEMPLATE_LOW. PRIVACY_TEMPLATE_MAX = PRIVACY_TEMPLATE_LOW, } /// Specifies the PrivacyType for which privacy settings are being set or retrieved. [PInvokeData("wininet.h")] public enum PrivacyType { /// Refers to privacy settings for first party cookies. PRIVACY_TYPE_FIRST_PARTY = 0, /// Refers to privacy settings for third party cookies. PRIVACY_TYPE_THIRD_PARTY = 1, } /// Automation detection type. [PInvokeData("wininet.h", MSDNShortId = "4e94ab0c-0f39-4e6e-a272-6beff61e97c6")] [Flags] public enum PROXY_AUTO_DETECT_TYPE { /// Use a Dynamic Host Configuration Protocol (DHCP) search to identify the proxy. PROXY_AUTO_DETECT_TYPE_DHCP = 1, /// Use a well qualified name search to identify the proxy. PROXY_AUTO_DETECT_TYPE_DNS_A = 2 } /// Stores data in the specified file in the Internet cache and associates it with the specified URL. /// /// Pointer to a string variable that contains the source name of the cache entry. The name string must be unique and should not /// contain any escape characters. /// /// /// Pointer to a string variable that contains the name of the local file that is being cached. This should be the same name as that /// returned by CreateUrlCacheEntryA. /// /// /// FILETIME structure that contains the expire date and time (in Greenwich mean time) of the file that is being cached. If the /// expire date and time is unknown, set this parameter to zero. /// /// /// FILETIME structure that contains the last modified date and time (in Greenwich mean time) of the URL that is being cached. If /// the last modified date and time is unknown, set this parameter to zero. /// /// /// /// A bitmask indicating the type of cache entry and its properties. The cache entry types include: history entries /// (URLHISTORY_CACHE_ENTRY), cookie entries (COOKIE_CACHE_ENTRY), and normal cached content (NORMAL_CACHE_ENTRY). /// /// This parameter can be zero or more of the following property flags, and cache type flags listed below. /// /// /// Value /// Meaning /// /// /// COOKIE_CACHE_ENTRY /// Cookie cache entry. /// /// /// EDITED_CACHE_ENTRY /// Cache entry file that has been edited externally. This cache entry type is exempt from scavenging. /// /// /// NORMAL_CACHE_ENTRY /// Normal cache entry; can be deleted to recover space for new entries. /// /// /// SPARSE_CACHE_ENTRY /// Partial response cache entry. /// /// /// STICKY_CACHE_ENTRY /// Sticky cache entry; exempt from scavenging. /// /// /// TRACK_OFFLINE_CACHE_ENTRY /// Not currently implemented. /// /// /// TRACK_ONLINE_CACHE_ENTRY /// Not currently implemented. /// /// /// URLHISTORY_CACHE_ENTRY /// Visited link cache entry. /// /// /// /// /// Pointer to the buffer that contains the header information. If this parameter is not NULL, the header information is /// treated as extended attributes of the URL that are returned in the lpHeaderInfo member of the INTERNET_CACHE_ENTRY_INFO structure. /// /// /// Size of the header information, in TCHARs. If lpHeaderInfo is not NULL, this value is assumed to indicate the size /// of the buffer that stores the header information. An application can maintain headers as part of the data and provide /// cchHeaderInfo together with a NULL value for lpHeaderInfo. /// /// This parameter is reserved and must be NULL. /// Pointer to a string that contains the original URL, if redirection has occurred. /// /// /// Returns TRUE if successful, or FALSE otherwise. To get extended error information, call GetLastError. The /// following are possible error values. /// /// /// /// Return code /// Description /// /// /// ERROR_DISK_FULL /// The cache storage is full. /// /// /// ERROR_FILE_NOT_FOUND /// The specified local file is not found. /// /// /// /// /// /// The STICKY_CACHE_ENTRY type is used to make cache entries exempt from scavenging. The default exempt time for entries set using /// CommitUrlCacheEntryA is ten minutes. The exempt time can be changed by setting the expires time parameter in the /// INTERNET_CACHE_ENTRY_INFO structure in the call to the SetUrlCacheEntryInfo function. /// /// /// If the cache storage is full, CommitUrlCacheEntryA invokes cache cleanup to make space for this new file. If the cache /// entry already exists, the function overwrites the entry if it is not in use. An entry is in use when it has been retrieved with /// either RetrieveUrlCacheEntryStream or RetrieveUrlCacheEntryFile. /// /// /// Clients that add entries to the cache should set the headers to at least "HTTP/1.0 200 OK\r\n\r\n"; otherwise, Microsoft /// Internet Explorer and other client applications should disregard the entry. /// /// See Caching for example code calling CreateUrlCacheEntryA. /// /// Like all other aspects of the WinINet API, this function cannot be safely called from within DllMain or the constructors and /// destructors of global objects. /// /// /// Note WinINet does not support server implementations. In addition, it should not be used from a service. For server /// implementations or services use Microsoft Windows HTTP Services (WinHTTP). /// /// // https://docs.microsoft.com/en-us/windows/win32/api/wininet/nf-wininet-commiturlcacheentrya BOOLAPI CommitUrlCacheEntryA( LPCSTR // lpszUrlName, LPCSTR lpszLocalFileName, FILETIME ExpireTime, FILETIME LastModifiedTime, DWORD CacheEntryType, LPBYTE lpHeaderInfo, // DWORD cchHeaderInfo, LPCSTR lpszFileExtension, LPCSTR lpszOriginalUrl ); [DllImport(Lib.WinInet, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("wininet.h", MSDNShortId = "4bd21b30-cac5-482b-9826-b5a4ffeeebe9")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool CommitUrlCacheEntry(string lpszUrlName, string lpszLocalFileName, [Optional] FILETIME ExpireTime, [Optional] FILETIME LastModifiedTime, [Optional] CACHE_ENTRY_TYPE CacheEntryType, [Optional] string lpHeaderInfo, [Optional] uint cchHeaderInfo, [Optional] string lpszFileExtension, [Optional] string lpszOriginalUrl); /// /// The CreateMD5SSOHash function obtains the default Microsoft Passport password for a specified account or realm, creates /// an MD5 hash from it using a specified wide-character challenge string, and returns the result as a string of hexadecimal digit bytes. /// /// Pointer to the wide-character challenge string to use for the MD5 hash. /// /// Pointer to a string that names a realm for which to obtain the password. This parameter is ignored unless pwszTarget is /// NULL. If both pwszTarget and pwszRealm are NULL, the default realm is used. /// /// /// Pointer to a string that names an account for which to obtain the password. If pwszTarget is NULL, the realm indicated by /// pwszRealm is used. /// /// /// Pointer to an output buffer into which the MD5 hash is returned in hex string format. This buffer must be at least 33 bytes long. /// /// Returns TRUE if successful, or FALSE otherwise. /// /// /// Once the CreateMD5SSOHash function successfully obtains the Microsoft Passport password for the specified account or /// realm, it converts both the challenge string and the password from wide characters to multi-byte (generally 8-bit) characters, /// concatenates them, and uses the RSA library to generate an MD5 hash from the resulting key. It then converts the hash into a /// null-terminated string of 8-bit hexadecimal digits (using lowercase letters) which it places in the buffer pointed to by /// the pbHexHash parameter. /// /// /// The output buffer pointed to by pbHexHash must therefore be long enough to accept two bytes for each of the 16 bytes of the /// hash, plus a terminating null character, for a total of 33 bytes. /// /// /// Like all other aspects of the WinINet API, this function cannot be safely called from within DllMain or the constructors and /// destructors of global objects. /// /// /// Note WinINet does not support server implementations. In addition, it should not be used from a service. For server /// implementations or services use Microsoft Windows HTTP Services (WinHTTP). /// /// // https://docs.microsoft.com/en-us/windows/win32/api/wininet/nf-wininet-createmd5ssohash BOOLAPI CreateMD5SSOHash( PWSTR // pszChallengeInfo, PWSTR pwszRealm, PWSTR pwszTarget, PBYTE pbHexHash ); [DllImport(Lib.WinInet, SetLastError = true, ExactSpelling = true)] [PInvokeData("wininet.h", MSDNShortId = "9aba22d7-a1a9-4b90-bfc6-78df8a8d0ce5")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool CreateMD5SSOHash([MarshalAs(UnmanagedType.LPWStr)] string pszChallengeInfo, [MarshalAs(UnmanagedType.LPWStr), Optional] string pwszRealm, [MarshalAs(UnmanagedType.LPWStr), Optional] string pwszTarget, byte[] pbHexHash); /// /// /// Creates a cache container in the specified cache path to hold cache entries based on the specified name, cache prefix, and /// container type. /// /// This API is deprecated. Please use the Extensible Storage Engine instead. /// /// The name to give to the cache. /// The cache prefix to base the cache on. /// The cache prefix to create the cache in. /// The size limit of the cache in whole kilobytes, or 0 for the default size. /// The container type to base the cache on. /// This parameter is reserved and must be 0. /// This parameter is reserved and must be NULL. /// This parameter is reserved and must be NULL. /// Returns TRUE if successful, or FALSE otherwise. To get extended error information, call GetLastError. // https://docs.microsoft.com/en-us/windows/win32/api/winineti/nf-winineti-createurlcachecontainera BOOLAPI // CreateUrlCacheContainerA( LPCSTR Name, LPCSTR lpCachePrefix, LPCSTR lpszCachePath, DWORD KBCacheLimit, DWORD dwContainerType, // DWORD dwOptions, LPVOID pvBuffer, LPDWORD cbBuffer ); [DllImport(Lib.WinInet, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("winineti.h", MSDNShortId = "19b518cc-2f02-49c3-bedc-f5d633cc635d")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool CreateUrlCacheContainer(string Name, string lpCachePrefix, string lpszCachePath, [Optional] uint KBCacheLimit, INTERNET_CACHE_CONTAINER dwContainerType, uint dwOptions = 0, IntPtr pvBuffer = default, IntPtr cbBuffer = default); /// Creates a local file name for saving the cache entry based on the specified URL and the file name extension. /// /// Pointer to a string value that contains the name of the URL. The string must contain a value; an empty string will cause /// CreateUrlCacheEntry to fail. In addition, the string must not contain any escape characters. /// /// /// Expected size of the file needed to store the data that corresponds to the source entity, in TCHARs. If the expected size /// is unknown, set this value to zero. /// /// Pointer to a string value that contains an extension name of the file in the local storage. /// /// Pointer to a buffer that receives the file name. The buffer should be large enough to store the path of the created file (at /// least MAX_PATH characters in length). /// /// This parameter is reserved and must be 0. /// /// If the function succeeds, the function returns TRUE. /// If the function fails, it returns FALSE. To get extended error information, call GetLastError. /// /// /// /// After CreateUrlCacheEntry is called, the application can write directly into the file in local storage. When the file is /// completely received, the caller should call CommitUrlCacheEntry to commit the entry in the cache. /// /// /// WinINet attempts to decode Unicode parameters according to the system code page. Applications should ensure that Unicode /// parameters are properly encoded for the system code page. Applications can set the system code page with InternetSetOption as /// shown in the following code example: /// /// If the Unicode parameter is not properly encoded to the system code page, WinINet attempts UTF8 decoding. /// /// When items are retrieved from the cache, the system code page that was used to place the item in the cache must match the /// current system code page for the user. For applications running under IE6 and earlier, if decoding for the system code page /// fails, WinINet attempts UTF8 decoding. /// /// /// Like all other aspects of the WinINet API, this function cannot be safely called from within DllMain or the constructors and /// destructors of global objects. /// /// /// Note WinINet does not support server implementations. In addition, it should not be used from a service. For server /// implementations or services use Microsoft Windows HTTP Services (WinHTTP). /// /// // https://docs.microsoft.com/en-us/windows/win32/api/wininet/nf-wininet-createurlcacheentryw BOOLAPI CreateUrlCacheEntryW( LPCWSTR // lpszUrlName, DWORD dwExpectedFileSize, LPCWSTR lpszFileExtension, LPWSTR lpszFileName, DWORD dwReserved ); [DllImport(Lib.WinInet, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("wininet.h", MSDNShortId = "9a58cf05-2306-4a0f-876d-85f5e91c5a2b")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool CreateUrlCacheEntry(string lpszUrlName, uint dwExpectedFileSize, string lpszFileExtension, StringBuilder lpszFileName, uint dwReserved = 0); /// Generates cache group identifications. /// /// Controls the creation of the cache group. This parameter can be set to CACHEGROUP_FLAG_GIDONLY, which causes /// CreateUrlCacheGroup to generate a unique GROUPID, but does not create a physical group. /// /// This parameter is reserved and must be NULL. /// /// Returns a valid GROUPID if successful, or FALSE otherwise. To get specific error information, call GetLastError. /// /// /// Note WinINet does not support server implementations. In addition, it should not be used from a service. For server /// implementations or services use Microsoft Windows HTTP Services (WinHTTP). /// // https://docs.microsoft.com/en-us/windows/win32/api/wininet/nf-wininet-createurlcachegroup void CreateUrlCacheGroup( DWORD // dwFlags, LPVOID lpReserved ); [DllImport(Lib.WinInet, SetLastError = true, ExactSpelling = true)] [PInvokeData("wininet.h", MSDNShortId = "bea0bc3b-75fb-4147-a4bd-f4290dfbf290")] public static extern long CreateUrlCacheGroup([Optional] CACHEGROUP_FLAG dwFlags, IntPtr lpReserved = default); /// /// /// [Some information relates to pre-released product which may be substantially modified before it's commercially released. /// Microsoft makes no warranties, express or implied, with respect to the information provided here.] /// /// Deletes a cache container (which contains cache entries) based on the specified name. /// /// The name of the cache container to be deleted. /// This parameter is reserved, and must be 0. /// Returns TRUE if successful, or FALSE otherwise. To get extended error information, call GetLastError. /// /// Note WinINet does not support server implementations. In addition, it should not be used from a service nor when /// impersonating a security context. For server implementations or services use Microsoft Windows HTTP Services (WinHTTP). /// // https://docs.microsoft.com/en-us/windows/win32/api/winineti/nf-winineti-deleteurlcachecontainera BOOLAPI // DeleteUrlCacheContainerA( LPCSTR Name, DWORD dwOptions ); [DllImport(Lib.WinInet, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("winineti.h", MSDNShortId = "97F46974-9B20-46C6-B742-4BA5C60491DA")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool DeleteUrlCacheContainer(string Name, uint dwOptions = 0); /// Removes the file associated with the source name from the cache, if the file exists. /// Pointer to a string that contains the name of the source that corresponds to the cache entry. /// /// /// Returns TRUE if successful, or FALSE otherwise. To get extended error information, call GetLastError. Possible /// error values include the following. /// /// /// /// Return code /// Description /// /// /// ERROR_ACCESS_DENIED /// The file is locked or in use. The entry is marked and deleted when the file is unlocked. /// /// /// ERROR_FILE_NOT_FOUND /// The file is not in the cache. /// /// /// /// /// Note WinINet does not support server implementations. In addition, it should not be used from a service. For server /// implementations or services use Microsoft Windows HTTP Services (WinHTTP). /// // https://docs.microsoft.com/en-us/windows/win32/api/wininet/nf-wininet-deleteurlcacheentry BOOLAPI DeleteUrlCacheEntry( LPCSTR // lpszUrlName ); [DllImport(Lib.WinInet, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("wininet.h", MSDNShortId = "bb765cba-6662-4dca-8f9f-3f35e37da28a")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool DeleteUrlCacheEntry(string lpszUrlName); /// Releases the specified GROUPID and any associated state in the cache index file. /// ID of the cache group to be released. /// /// Controls the cache group deletion. This can be set to any member of the cache group constants. When this parameter is set to /// CACHEGROUP_FLAG_FLUSHURL_ONDELETE, it causes DeleteUrlCacheGroup to delete all of the cache entries associated with this /// group, unless the entry belongs to another group. /// /// This parameter is reserved and must be NULL. /// Returns TRUE if successful, or FALSE otherwise. To get specific error information, call GetLastError. /// /// Note WinINet does not support server implementations. In addition, it should not be used from a service. For server /// implementations or services use Microsoft Windows HTTP Services (WinHTTP). /// // https://docs.microsoft.com/en-us/windows/win32/api/wininet/nf-wininet-deleteurlcachegroup BOOLAPI DeleteUrlCacheGroup( GROUPID // GroupId, DWORD dwFlags, LPVOID lpReserved ); [DllImport(Lib.WinInet, SetLastError = true, ExactSpelling = true)] [PInvokeData("wininet.h", MSDNShortId = "f1ff70db-36b7-4805-8f23-e3920acf0d11")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool DeleteUrlCacheGroup(long GroupId, CACHEGROUP_FLAG dwFlags, IntPtr lpReserved = default); /// Attempts to determine the location of a WPAD autoproxy script. /// Pointer to a buffer to receive the URL from which a WPAD autoproxy script can be downloaded. /// Size of the buffer pointed to by lpszAutoProxyUrl, in bytes. /// /// Automation detection type. This parameter can be one or both of the following values. /// /// /// Value /// Meaning /// /// /// PROXY_AUTO_DETECT_TYPE_DHCP /// Use a Dynamic Host Configuration Protocol (DHCP) search to identify the proxy. /// /// /// PROXY_AUTO_DETECT_TYPE_DNS_A /// Use a well qualified name search to identify the proxy. /// /// /// /// Returns TRUE if successful, or FALSE otherwise. To get extended error information, call GetLastError. /// /// Note WinINet does not support server implementations. In addition, it should not be used from a service. For server /// implementations or services use Microsoft Windows HTTP Services (WinHTTP). /// // https://docs.microsoft.com/en-us/windows/win32/api/wininet/nf-wininet-detectautoproxyurl BOOLAPI DetectAutoProxyUrl( PSTR // pszAutoProxyUrl, DWORD cchAutoProxyUrl, DWORD dwDetectFlags ); [DllImport(Lib.WinInet, SetLastError = true, ExactSpelling = true)] [PInvokeData("wininet.h", MSDNShortId = "4e94ab0c-0f39-4e6e-a272-6beff61e97c6")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool DetectAutoProxyUrl([MarshalAs(UnmanagedType.LPStr)] StringBuilder pszAutoProxyUrl, uint cchAutoProxyUrl, PROXY_AUTO_DETECT_TYPE dwDetectFlags); /// Closes the specified cache enumeration handle. /// Handle returned by a previous call to the FindFirstUrlCacheEntry function. /// Returns TRUE if successful, or FALSE otherwise. To get extended error information, call GetLastError. /// /// Note WinINet does not support server implementations. In addition, it should not be used from a service. For server /// implementations or services use Microsoft Windows HTTP Services (WinHTTP). /// // https://docs.microsoft.com/en-us/windows/win32/api/wininet/nf-wininet-findcloseurlcache BOOLAPI FindCloseUrlCache( HANDLE // hEnumHandle ); [DllImport(Lib.WinInet, SetLastError = true, ExactSpelling = true)] [PInvokeData("wininet.h", MSDNShortId = "54fc7bea-4cc1-4034-93c3-49ec88817648")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool FindCloseUrlCache(HFINDCACHE hEnumHandle); /// Begins the enumeration of the Internet cache. /// /// A pointer to a string that contains the source name pattern to search for. This parameter can only be set to "cookie:", /// "visited:", or NULL. Set this parameter to "cookie:" to enumerate the cookies or "visited:" to enumerate the URL History /// entries in the cache. If this parameter is NULL, FindFirstUrlCacheEntry returns all content entries in the cache. /// /// Pointer to an INTERNET_CACHE_ENTRY_INFO structure. /// /// Pointer to a variable that specifies the size of the lpFirstCacheEntryInfo buffer, in bytes. When the function returns, the /// variable contains the number of bytes copied to the buffer, or the required size needed to retrieve the cache entry, in bytes. /// /// /// /// Returns a handle that the application can use in the FindNextUrlCacheEntry function to retrieve subsequent entries in the cache. /// If the function fails, the return value is NULL. To get extended error information, call GetLastError. /// /// /// ERROR_INSUFFICIENT_BUFFER indicates that the size of lpFirstCacheEntryInfo as specified by lpdwFirstCacheEntryInfoBufferSize is /// not sufficient to contain all the information. The value returned in lpdwFirstCacheEntryInfoBufferSize indicates the buffer size /// necessary to contain all the information. /// /// /// /// /// The handle returned from FindFirstUrlCacheEntry is used in all subsequent calls to FindNextUrlCacheEntry. At the end of /// the enumeration, the application should call FindCloseUrlCache. /// /// /// FindFirstUrlCacheEntry and FindNextUrlCacheEntry return variable size information. If ERROR_INSUFFICIENT_BUFFER is /// returned, the application should allocate a buffer of the size specified by lpdwFirstCacheEntryInfoBufferSize. For more /// information, see Using Buffers. /// /// /// Like all other aspects of the WinINet API, this function cannot be safely called from within DllMain or the constructors and /// destructors of global objects. /// /// /// Note WinINet does not support server implementations. In addition, it should not be used from a service. For server /// implementations or services use Microsoft Windows HTTP Services (WinHTTP). /// /// // https://docs.microsoft.com/en-us/windows/win32/api/wininet/nf-wininet-findfirsturlcacheentrya void FindFirstUrlCacheEntryA( // LPCSTR lpszUrlSearchPattern, LPINTERNET_CACHE_ENTRY_INFOA lpFirstCacheEntryInfo, LPDWORD lpcbCacheEntryInfo ); [DllImport(Lib.WinInet, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("wininet.h", MSDNShortId = "e8407284-846b-4080-b75b-4805330e0f95")] public static extern HFINDCACHE FindFirstUrlCacheEntry(string lpszUrlSearchPattern, IntPtr lpFirstCacheEntryInfo, ref uint lpcbCacheEntryInfo); /// Initiates the enumeration of the cache groups in the Internet cache. /// This parameter is reserved and must be 0. /// /// Filters to be used. This parameter can be zero or one of the following values. /// /// /// Value /// Meaning /// /// /// CACHEGROUP_SEARCH_ALL /// Search all cache groups. /// /// /// CACHEGROUP_SEARCH_BYURL /// Not currently implemented. /// /// /// /// This parameter is reserved and must be NULL. /// This parameter is reserved and must be 0. /// Pointer to the ID of the first cache group that matches the search criteria. /// This parameter is reserved and must be NULL. /// /// Returns a valid handle to the first item in the enumeration if successful, or NULL otherwise. To get specific error /// information, call GetLastError. If the function finds no matching files, GetLastError returns ERROR_NO_MORE_FILES. /// /// /// /// The handle returned from FindFirstUrlCacheGroup is used in subsequent calls to FindNextUrlCacheGroup. At the end of the /// enumeration, the application should call FindCloseUrlCache. /// /// /// Like all other aspects of the WinINet API, this function cannot be safely called from within DllMain or the constructors and /// destructors of global objects. /// /// /// Note WinINet does not support server implementations. In addition, it should not be used from a service. For server /// implementations or services use Microsoft Windows HTTP Services (WinHTTP). /// /// // https://docs.microsoft.com/en-us/windows/win32/api/wininet/nf-wininet-findfirsturlcachegroup void FindFirstUrlCacheGroup( DWORD // dwFlags, DWORD dwFilter, LPVOID lpSearchCondition, DWORD dwSearchCondition, GROUPID *lpGroupId, LPVOID lpReserved ); [DllImport(Lib.WinInet, SetLastError = true, ExactSpelling = true)] [PInvokeData("wininet.h", MSDNShortId = "a333cbc6-a880-4b1c-be0d-abb083909638")] public static extern HFINDCACHE FindFirstUrlCacheGroup([Optional] uint dwFlags, [Optional] CACHEGROUP_SEARCH dwFilter, [Optional] IntPtr lpSearchCondition, [Optional] uint dwSearchCondition, out long lpGroupId, [Optional] IntPtr lpReserved); /// Retrieves the next entry in the Internet cache. /// Handle to the enumeration obtained from a previous call to FindFirstUrlCacheEntry. /// /// Pointer to an INTERNET_CACHE_ENTRY_INFO structure that receives information about the cache entry. /// /// /// Pointer to a variable that specifies the size of the lpNextCacheEntryInfo buffer, in bytes. When the function returns, the /// variable contains the number of bytes copied to the buffer, or the size of the buffer required to retrieve the cache entry, in bytes. /// /// /// /// Returns TRUE if successful, or FALSE otherwise. To get extended error information, call GetLastError. Possible /// error values include the following. /// /// /// /// Return code /// Description /// /// /// ERROR_INSUFFICIENT_BUFFER /// /// The size of lpNextCacheEntryInfo as specified by lpdwNextCacheEntryInfoBufferSize is not sufficient to contain all the /// information. The value returned in lpdwNextCacheEntryInfoBufferSize indicates the buffer size necessary to contain all the information. /// /// /// /// ERROR_NO_MORE_ITEMS /// The enumeration completed. /// /// /// /// /// Continue to call FindNextUrlCacheEntry until the last item in the cache is returned. /// /// Like all other aspects of the WinINet API, this function cannot be safely called from within DllMain or the constructors and /// destructors of global objects. /// /// /// Note WinINet does not support server implementations. In addition, it should not be used from a service. For server /// implementations or services use Microsoft Windows HTTP Services (WinHTTP). /// /// // https://docs.microsoft.com/en-us/windows/win32/api/wininet/nf-wininet-findnexturlcacheentrya BOOLAPI FindNextUrlCacheEntryA( // HANDLE hEnumHandle, LPINTERNET_CACHE_ENTRY_INFOA lpNextCacheEntryInfo, LPDWORD lpcbCacheEntryInfo ); [DllImport(Lib.WinInet, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("wininet.h", MSDNShortId = "776bf73e-00f3-46a1-a8c7-5eb365e9a518")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool FindNextUrlCacheEntry(HFINDCACHE hEnumHandle, IntPtr lpNextCacheEntryInfo, ref uint lpcbCacheEntryInfo); /// Retrieves the next cache group in a cache group enumeration started by FindFirstUrlCacheGroup. /// The cache group enumeration handle, which is returned by FindFirstUrlCacheGroup. /// Pointer to a variable that receives the cache group identifier. /// This parameter is reserved and must be NULL. /// Returns TRUE if successful, or FALSE otherwise. To get specific error information, call GetLastError. /// /// Continue to call FindNextUrlCacheGroup until the last item in the cache is returned. /// /// Like all other aspects of the WinINet API, this function cannot be safely called from within DllMain or the constructors and /// destructors of global objects. /// /// /// Note WinINet does not support server implementations. In addition, it should not be used from a service. For server /// implementations or services use Microsoft Windows HTTP Services (WinHTTP). /// /// // https://docs.microsoft.com/en-us/windows/win32/api/wininet/nf-wininet-findnexturlcachegroup BOOLAPI FindNextUrlCacheGroup( HANDLE // hFind, GROUPID *lpGroupId, LPVOID lpReserved ); [DllImport(Lib.WinInet, SetLastError = true, ExactSpelling = true)] [PInvokeData("wininet.h", MSDNShortId = "f3cbe67c-c069-404c-8ca4-d18b35cc4c4a")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool FindNextUrlCacheGroup(HFINDCACHE hFind, out long lpGroupId, IntPtr lpReserved = default); /// Enumerates the Internet cache. /// /// A pointer to a string that contains the source name pattern to search for. This parameter can only be set to "cookie:", /// "visited:", or NULL. Set this parameter to "cookie:" to enumerate the cookies or "visited:" to enumerate the URL History /// entries in the cache. If this parameter is NULL, FindFirstUrlCacheEntry returns all content entries in the cache. /// /// /// An enumeration of structures which parallel the values in the native structure. /// public static IEnumerable FindUrlCacheEntries(string lpszUrlSearchPattern = null) { using (var mem = new SafeHGlobalHandle(1024)) { uint sz = mem.Size; var h = FindFirstUrlCacheEntry(lpszUrlSearchPattern, mem, ref sz); if (h.IsNull) { Win32Error.ThrowLastErrorUnless(Win32Error.ERROR_INSUFFICIENT_BUFFER); mem.Size = sz; h = FindFirstUrlCacheEntry(lpszUrlSearchPattern, mem, ref sz); if (h.IsNull) Win32Error.ThrowLastError(); } yield return new INTERNET_CACHE_ENTRY_INFO_MGD(mem.ToStructure()); try { do { if (!FindNextUrlCacheEntry(h, mem, ref sz)) { var err = Win32Error.GetLastError(); if (err == Win32Error.ERROR_NO_MORE_ITEMS) break; err.ThrowUnless(Win32Error.ERROR_INSUFFICIENT_BUFFER); mem.Size = sz; if (!FindNextUrlCacheEntry(h, mem, ref sz)) Win32Error.ThrowLastErrorUnless(Win32Error.ERROR_NO_MORE_ITEMS); } yield return new INTERNET_CACHE_ENTRY_INFO_MGD(mem.ToStructure()); } while (true); } finally { FindCloseUrlCache(h); } } } /// Initiates the enumeration of the cache groups in the Internet cache. /// An enumeration of GROUPID values. public static IEnumerable FindUrlCacheGroups() { var h = FindFirstUrlCacheGroup(lpGroupId: out var id); if (h.IsNull) Win32Error.ThrowLastErrorUnless(Win32Error.ERROR_NO_MORE_ITEMS); var done = h.IsNull; while (!done) { yield return id; if (!FindNextUrlCacheGroup(h, out id)) { Win32Error.ThrowLastErrorUnless(Win32Error.ERROR_NO_MORE_ITEMS); done = true; } } } /// The FtpCommand function sends commands directly to an FTP server. /// A handle returned from a call to InternetConnect. /// /// A Boolean value that indicates whether the application expects a data connection to be established by the FTP server. This must /// be set to TRUE if a data connection is expected, or FALSE otherwise. /// /// /// A parameter that can be set to one of the following values. /// /// /// Value /// Meaning /// /// /// FTP_TRANSFER_TYPE_ASCII /// Transfers the file using the FTP ASCII (Type A) transfer method. Control and formatting data is converted to local equivalents. /// /// /// FTP_TRANSFER_TYPE_BINARY /// /// Transfers the file using the FTP Image (Type I) transfer method. The file is transferred exactly with no changes. This is the /// default transfer method. /// /// /// /// /// A pointer to a string that contains the command to send to the FTP server. /// /// A pointer to a variable that contains an application-defined value used to identify the application context in callback operations. /// /// /// A pointer to a handle that is created if a valid data socket is opened. The fExpectResponse parameter must be set to TRUE /// for phFtpCommand to be filled. /// /// Returns TRUE if successful, or FALSE otherwise. To get a specific error message, call GetLastError. /// /// /// GetLastError can return ERROR_INTERNET_NO_DIRECT_ACCESS if the client application is offline. If one or more of the parameters /// are invalid, GetLastError will return ERROR_INVALID_PARAMETER. /// /// /// Like all other aspects of the WinINet API, this function cannot be safely called from within DllMain or the constructors and /// destructors of global objects. /// /// /// Note WinINet does not support server implementations. In addition, it should not be used from a service. For server /// implementations or services use Microsoft Windows HTTP Services (WinHTTP). /// /// // https://docs.microsoft.com/en-us/windows/win32/api/wininet/nf-wininet-ftpcommanda BOOLAPI FtpCommandA( HINTERNET hConnect, BOOL // fExpectResponse, DWORD dwFlags, LPCSTR lpszCommand, DWORD_PTR dwContext, HINTERNET *phFtpCommand ); [DllImport(Lib.WinInet, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("wininet.h", MSDNShortId = "cd12f52c-80d6-4aee-96c8-cb3cafcf0a6a")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool FtpCommand(HINTERNET hConnect, [MarshalAs(UnmanagedType.Bool)] bool fExpectResponse, FTP_TRANSER_TYPE dwFlags, string lpszCommand, [Optional] IntPtr dwContext, out SafeHINTERNET phFtpCommand); /// Creates a new directory on the FTP server. /// Handle returned by a previous call to InternetConnect using INTERNET_SERVICE_FTP. /// /// Pointer to a null-terminated string that contains the name of the directory to be created. This can be either a fully qualified /// path or a name relative to the current directory. /// /// /// Returns TRUE if successful, or FALSE otherwise. To get a specific error message, call GetLastError. If the error /// message indicates that the FTP server denied the request to create a directory, use InternetGetLastResponseInfo to determine why. /// /// /// /// An application should use FtpGetCurrentDirectory to determine the remote site's current working directory instead of assuming /// that the remote system uses a hierarchical naming scheme for directories. /// /// The lpszDirectory parameter can be either partially or fully qualified file names relative to the current directory. /// /// Like all other aspects of the WinINet API, this function cannot be safely called from within DllMain or the constructors and /// destructors of global objects. /// /// /// Note WinINet does not support server implementations. In addition, it should not be used from a service. For server /// implementations or services use Microsoft Windows HTTP Services (WinHTTP). /// /// // https://docs.microsoft.com/en-us/windows/win32/api/wininet/nf-wininet-ftpcreatedirectorya BOOLAPI FtpCreateDirectoryA( HINTERNET // hConnect, LPCSTR lpszDirectory ); [DllImport(Lib.WinInet, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("wininet.h", MSDNShortId = "51a33c5b-4e82-4148-8a3f-0cf7c0a8bac0")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool FtpCreateDirectory(HINTERNET hConnect, string lpszDirectory); /// Deletes a file stored on the FTP server. /// Handle returned by a previous call to InternetConnect using INTERNET_SERVICE_FTP. /// Pointer to a null-terminated string that contains the name of the file to be deleted. /// Returns TRUE if successful, or FALSE otherwise. To get a specific error message, call GetLastError. /// /// The lpszFileName parameter can be either partially or fully qualified file names relative to the current directory. /// /// Like all other aspects of the WinINet API, this function cannot be safely called from within DllMain or the constructors and /// destructors of global objects. /// /// /// Note WinINet does not support server implementations. In addition, it should not be used from a service. For server /// implementations or services use Microsoft Windows HTTP Services (WinHTTP). /// /// // https://docs.microsoft.com/en-us/windows/win32/api/wininet/nf-wininet-ftpdeletefilea BOOLAPI FtpDeleteFileA( HINTERNET hConnect, // LPCSTR lpszFileName ); [DllImport(Lib.WinInet, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("wininet.h", MSDNShortId = "16723c97-fd6f-40c2-844d-fc6d2dcc1a32")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool FtpDeleteFile(HINTERNET hConnect, string lpszFileName); /// /// Searches the specified directory of the given FTP session. File and directory entries are returned to the application in the /// WIN32_FIND_DATA structure. /// /// Handle to an FTP session returned from InternetConnect. /// /// Pointer to a null-terminated string that specifies a valid directory path or file name for the FTP server's file system. /// The string can contain wildcards, but no blank spaces are allowed. If the value of lpszSearchFile is NULL or if it is an /// empty string, the function finds the first file in the current directory on the server. /// /// Pointer to a WIN32_FIND_DATA structure that receives information about the found file or directory. /// /// Controls the behavior of this function. This parameter can be a combination of the following values. /// INTERNET_FLAG_HYPERLINK /// INTERNET_FLAG_NEED_FILE /// INTERNET_FLAG_NO_CACHE_WRITE /// INTERNET_FLAG_RELOAD /// INTERNET_FLAG_RESYNCHRONIZE /// /// /// Pointer to a variable that specifies the application-defined value that associates this search with any application data. This /// parameter is used only if the application has already called InternetSetStatusCallback to set up a status callback function. /// /// /// Returns a valid handle for the request if the directory enumeration was started successfully, or returns NULL otherwise. /// To get a specific error message, call GetLastError. If GetLastError returns ERROR_INTERNET_EXTENDED_ERROR, as in the case /// where the function finds no matching files, call the InternetGetLastResponseInfo function to retrieve the extended error text, /// as documented in Handling Errors. /// /// /// /// For FtpFindFirstFile, file times returned in the WIN32_FIND_DATA structure are in the local time zone, not in a /// coordinated universal time (UTC) format. /// /// /// FtpFindFirstFile is similar to the FindFirstFile function. Note, however, that only one FtpFindFirstFile can occur /// at a time within a given FTP session. The enumerations, therefore, are correlated with the FTP session handle. This is because /// the FTP protocol allows only a single directory enumeration per session. /// /// /// After calling FtpFindFirstFile and until calling InternetCloseHandle, the application cannot call FtpFindFirstFile /// again on the given FTP session handle. If a call is made to FtpFindFirstFile on that handle, the function fails with /// ERROR_FTP_TRANSFER_IN_PROGRESS. After the calling application has finished using the HINTERNET handle returned by /// FtpFindFirstFile, it must be closed using the InternetCloseHandle function. /// /// /// After beginning a directory enumeration with FtpFindFirstFile, the InternetFindNextFile function can be used to continue /// the enumeration. /// /// /// Because the FTP protocol provides no standard means of enumerating, some of the common information about files, such as file /// creation date and time, is not always available or correct. When this happens, FtpFindFirstFile and InternetFindNextFile /// fill in unavailable information with a best guess based on available information. For example, creation and last access dates /// are often the same as the file's modification date. /// /// The application cannot call FtpFindFirstFile between calls to FtpOpenFile and InternetCloseHandle. /// /// Like all other aspects of the WinINet API, this function cannot be safely called from within DllMain or the constructors and /// destructors of global objects. /// /// /// Note WinINet does not support server implementations. In addition, it should not be used from a service. For server /// implementations or services use Microsoft Windows HTTP Services (WinHTTP). /// /// // https://docs.microsoft.com/en-us/windows/win32/api/wininet/nf-wininet-ftpfindfirstfilea void FtpFindFirstFileA( HINTERNET // hConnect, LPCSTR lpszSearchFile, LPWIN32_FIND_DATAA lpFindFileData, DWORD dwFlags, DWORD_PTR dwContext ); [DllImport(Lib.WinInet, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("wininet.h", MSDNShortId = "4f331f99-c52c-4744-a9a7-eeb09803862d")] public static extern SafeHINTERNET FtpFindFirstFile(HINTERNET hConnect, [Optional] string lpszSearchFile, out WIN32_FIND_DATA lpFindFileData, INTERNET_FLAG dwFlags, [Optional] IntPtr dwContext); /// Retrieves the current directory for the specified FTP session. /// Handle to an FTP session. /// Pointer to a null-terminated string that receives the absolute path of the current directory. /// /// Pointer to a variable that specifies the length of the buffer, in TCHARs. The buffer length must include room for a /// terminating null character. Using a length of MAX_PATH is sufficient for all paths. When the function returns, the /// variable receives the number of characters copied into the buffer. /// /// Returns TRUE if successful, or FALSE otherwise. To get a specific error message, call GetLastError. /// /// /// If the lpszCurrentDirectory buffer is not large enough, lpdwCurrentDirectory receives the number of bytes required to retrieve /// the full, current directory name. /// /// /// Like all other aspects of the WinINet API, this function cannot be safely called from within DllMain or the constructors and /// destructors of global objects. /// /// /// Note WinINet does not support server implementations. In addition, it should not be used from a service. For server /// implementations or services use Microsoft Windows HTTP Services (WinHTTP). /// /// // https://docs.microsoft.com/en-us/windows/win32/api/wininet/nf-wininet-ftpgetcurrentdirectorya BOOLAPI FtpGetCurrentDirectoryA( // HINTERNET hConnect, LPSTR lpszCurrentDirectory, LPDWORD lpdwCurrentDirectory ); [DllImport(Lib.WinInet, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("wininet.h", MSDNShortId = "1b757061-469b-4c11-9d0d-38b300216221")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool FtpGetCurrentDirectory(HINTERNET hConnect, StringBuilder lpszCurrentDirectory, ref uint lpdwCurrentDirectory); /// /// Retrieves a file from the FTP server and stores it under the specified file name, creating a new local file in the process. /// /// Handle to an FTP session. /// Pointer to a null-terminated string that contains the name of the file to be retrieved. /// /// Pointer to a null-terminated string that contains the name of the file to be created on the local system. /// /// /// Indicates whether the function should proceed if a local file of the specified name already exists. If fFailIfExists is /// TRUE and the local file exists, FtpGetFile fails. /// /// /// File attributes for the new file. This parameter can be any combination of the FILE_ATTRIBUTE_* flags used by the CreateFile function. /// /// /// /// Controls how the function will handle the file download. The first set of flag values indicates the conditions under which the /// transfer occurs. These transfer type flags can be used in combination with the second set of flags that control caching. /// /// The application can select one of these transfer type values. /// /// /// Value /// Meaning /// /// /// FTP_TRANSFER_TYPE_ASCII /// /// Transfers the file using FTP's ASCII (Type A) transfer method. Control and formatting information is converted to local equivalents. /// /// /// /// FTP_TRANSFER_TYPE_BINARY /// /// Transfers the file using FTP's Image (Type I) transfer method. The file is transferred exactly as it exists with no changes. /// This is the default transfer method. /// /// /// /// FTP_TRANSFER_TYPE_UNKNOWN /// Defaults to FTP_TRANSFER_TYPE_BINARY. /// /// /// INTERNET_FLAG_TRANSFER_ASCII /// Transfers the file as ASCII. /// /// /// INTERNET_FLAG_TRANSFER_BINARY /// Transfers the file as binary. /// /// /// /// The following flags determine how the caching of this file will be done. Any combination of the following flags can be used with /// the transfer type flag. /// /// /// /// Value /// Meaning /// /// /// INTERNET_FLAG_HYPERLINK /// /// Forces a reload if there was no Expires time and no LastModified time returned from the server when determining whether to /// reload the item from the network. /// /// /// /// INTERNET_FLAG_NEED_FILE /// Causes a temporary file to be created if the file cannot be cached. /// /// /// INTERNET_FLAG_RELOAD /// Forces a download of the requested file, object, or directory listing from the origin server, not from the cache. /// /// /// INTERNET_FLAG_RESYNCHRONIZE /// /// Reloads HTTP resources if the resource has been modified since the last time it was downloaded. All FTP resources are reloaded. /// Windows XP and Windows Server 2003 R2 and earlier: Gopher resources are also reloaded. /// /// /// /// /// /// Pointer to a variable that contains the application-defined value that associates this search with any application data. This is /// used only if the application has already called InternetSetStatusCallback to set up a status callback function. /// /// Returns TRUE if successful, or FALSE otherwise. To get a specific error message, call GetLastError. /// /// /// FtpGetFile is a high-level routine that handles all the bookkeeping and overhead associated with reading a file from an /// FTP server and storing it locally. An application that needs to retrieve file data only or that requires close control over the /// file transfer should use the FtpOpenFile and InternetReadFile functions. /// /// /// If the dwFlags parameter specifies FTP_TRANSFER_TYPE_ASCII, translation of the file data converts control and formatting /// characters to local equivalents. The default transfer is binary mode, where the file is downloaded in the same format as it is /// stored on the server. /// /// Both lpszRemoteFile and lpszNewFile can be either partially or fully qualified file names relative to the current directory. /// /// Like all other aspects of the WinINet API, this function cannot be safely called from within DllMain or the constructors and /// destructors of global objects. /// /// /// Note WinINet does not support server implementations. In addition, it should not be used from a service. For server /// implementations or services use Microsoft Windows HTTP Services (WinHTTP). /// /// // https://docs.microsoft.com/en-us/windows/win32/api/wininet/nf-wininet-ftpgetfilea BOOLAPI FtpGetFileA( HINTERNET hConnect, LPCSTR // lpszRemoteFile, LPCSTR lpszNewFile, BOOL fFailIfExists, DWORD dwFlagsAndAttributes, DWORD dwFlags, DWORD_PTR dwContext ); [DllImport(Lib.WinInet, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("wininet.h", MSDNShortId = "2de83924-dc48-42bc-8f08-b94e9eb88b6f")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool FtpGetFile(HINTERNET hConnect, string lpszRemoteFile, string lpszNewFile, [MarshalAs(UnmanagedType.Bool)] bool fFailIfExists, FileFlagsAndAttributes dwFlagsAndAttributes, INTERNET_FLAG dwFlags, [Optional] IntPtr dwContext); /// Retrieves the file size of the requested FTP resource. /// Handle returned from a call to FtpOpenFile. /// Pointer to the high-order unsigned long integer of the file size of the requested FTP resource. /// Returns the low-order unsigned long integer of the file size of the requested FTP resource. /// /// Note WinINet does not support server implementations. In addition, it should not be used from a service. For server /// implementations or services use Microsoft Windows HTTP Services (WinHTTP). /// // https://docs.microsoft.com/en-us/windows/win32/api/wininet/nf-wininet-ftpgetfilesize void FtpGetFileSize( HINTERNET hFile, // LPDWORD lpdwFileSizeHigh ); [DllImport(Lib.WinInet, SetLastError = true, ExactSpelling = true)] [PInvokeData("wininet.h", MSDNShortId = "f6cc696b-55b6-4d21-9401-fbb15062d0b4")] public static extern uint FtpGetFileSize(HINTERNET hFile, out uint lpdwFileSizeHigh); /// Initiates access to a remote file on an FTP server for reading or writing. /// Handle to an FTP session. /// Pointer to a null-terminated string that contains the name of the file to be accessed. /// File access. This parameter can be GENERIC_READ or GENERIC_WRITE, but not both. /// /// /// Conditions under which the transfers occur. The application should select one transfer type and any of the flags that indicate /// how the caching of the file will be controlled. /// /// The transfer type can be one of the following values. /// /// /// Value /// Meaning /// /// /// FTP_TRANSFER_TYPE_ASCII /// /// Transfers the file using FTP's ASCII (Type A) transfer method. Control and formatting information is converted to local equivalents. /// /// /// /// FTP_TRANSFER_TYPE_BINARY /// /// Transfers the file using FTP's Image (Type I) transfer method. The file is transferred exactly as it exists with no changes. /// This is the default transfer method. /// /// /// /// FTP_TRANSFER_TYPE_UNKNOWN /// Defaults to FTP_TRANSFER_TYPE_BINARY. /// /// /// INTERNET_FLAG_TRANSFER_ASCII /// Transfers the file as ASCII. /// /// /// INTERNET_FLAG_TRANSFER_BINARY /// Transfers the file as binary. /// /// /// The following values are used to control the caching of the file. The application can use one or more of these values. /// /// /// Value /// Meaning /// /// /// INTERNET_FLAG_HYPERLINK /// /// Forces a reload if there was no Expires time and no LastModified time returned from the server when determining whether to /// reload the item from the network. /// /// /// /// INTERNET_FLAG_NEED_FILE /// Causes a temporary file to be created if the file cannot be cached. /// /// /// INTERNET_FLAG_RELOAD /// Forces a download of the requested file, object, or directory listing from the origin server, not from the cache. /// /// /// INTERNET_FLAG_RESYNCHRONIZE /// /// Reloads HTTP resources if the resource has been modified since the last time it was downloaded. All FTP resources are reloaded. /// Windows XP and Windows Server 2003 R2 and earlier: Gopher resources are also reloaded. /// /// /// /// /// /// Pointer to a variable that contains the application-defined value that associates this search with any application data. This is /// only used if the application has already called InternetSetStatusCallback to set up a status callback function. /// /// Returns a handle if successful, or NULL otherwise. To retrieve a specific error message, call GetLastError. /// /// /// After calling FtpOpenFile and until calling InternetCloseHandle, all other calls to FTP functions on the same FTP session /// handle will fail and set the error message to ERROR_FTP_TRANSFER_IN_PROGRESS. After the calling application has finished using /// the HINTERNET handle returned by FtpOpenFile, it must be closed using the InternetCloseHandle function. /// /// /// Only one file can be open in a single FTP session. Therefore, no file handle is returned and the application simply uses the FTP /// session handle when necessary. /// /// The lpszFileName parameter can be either a partially or fully qualified file name relative to the current directory. /// /// Like all other aspects of the WinINet API, this function cannot be safely called from within DllMain or the constructors and /// destructors of global objects. /// /// /// Note WinINet does not support server implementations. In addition, it should not be used from a service. For server /// implementations or services use Microsoft Windows HTTP Services (WinHTTP). /// /// // https://docs.microsoft.com/en-us/windows/win32/api/wininet/nf-wininet-ftpopenfilea void FtpOpenFileA( HINTERNET hConnect, LPCSTR // lpszFileName, DWORD dwAccess, DWORD dwFlags, DWORD_PTR dwContext ); [DllImport(Lib.WinInet, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("wininet.h", MSDNShortId = "fb44d7bd-7868-4c53-aa4b-608d79c5bc7c")] public static extern SafeHINTERNET FtpOpenFile(HINTERNET hConnect, string lpszFileName, ACCESS_MASK dwAccess, FTP_TRANSER_TYPE dwFlags, [Optional] IntPtr dwContext); /// Stores a file on the FTP server. /// Handle to an FTP session. /// /// Pointer to a null-terminated string that contains the name of the file to be sent from the local system. /// /// /// Pointer to a null-terminated string that contains the name of the file to be created on the remote system. /// /// /// /// Conditions under which the transfers occur. The application should select one transfer type and any of the flags that control /// how the caching of the file will be controlled. /// /// The transfer type can be any one of the following values. /// /// /// Value /// Meaning /// /// /// FTP_TRANSFER_TYPE_ASCII /// /// Transfers the file using FTP's ASCII (Type A) transfer method. Control and formatting information is converted to local equivalents. /// /// /// /// FTP_TRANSFER_TYPE_BINARY /// /// Transfers the file using FTP's Image (Type I) transfer method. The file is transferred exactly as it exists with no changes. /// This is the default transfer method. /// /// /// /// FTP_TRANSFER_TYPE_UNKNOWN /// Defaults to FTP_TRANSFER_TYPE_BINARY. /// /// /// INTERNET_FLAG_TRANSFER_ASCII /// Transfers the file as ASCII. /// /// /// INTERNET_FLAG_TRANSFER_BINARY /// Transfers the file as binary. /// /// /// /// The following values are used to control the caching of the file. The application can use one or more of the following values. /// /// /// /// Value /// Meaning /// /// /// INTERNET_FLAG_HYPERLINK /// /// Forces a reload if there was no Expires time and no LastModified time returned from the server when determining whether to /// reload the item from the network. /// /// /// /// INTERNET_FLAG_NEED_FILE /// Causes a temporary file to be created if the file cannot be cached. /// /// /// INTERNET_FLAG_RELOAD /// Forces a download of the requested file, object, or directory listing from the origin server, not from the cache. /// /// /// INTERNET_FLAG_RESYNCHRONIZE /// /// Reloads HTTP resources if the resource has been modified since the last time it was downloaded. All FTP resources are reloaded. /// Windows XP and Windows Server 2003 R2 and earlier: Gopher resources are also reloaded. /// /// /// /// /// /// Pointer to a variable that contains the application-defined value that associates this search with any application data. This /// parameter is used only if the application has already called InternetSetStatusCallback to set up a status callback. /// /// Returns TRUE if successful, or FALSE otherwise. To get a specific error message, call GetLastError. /// /// /// FtpPutFile is a high-level routine that handles all the bookkeeping and overhead associated with reading a file locally /// and storing it on an FTP server. An application that needs to send file data only, or that requires close control over the file /// transfer, should use the FtpOpenFile and InternetWriteFile functions. /// /// /// If the dwFlags parameter specifies FILE_TRANSFER_TYPE_ASCII, translation of the file data converts control and formatting /// characters to local equivalents. /// /// /// Both lpszNewRemoteFile and lpszLocalFile can be either partially or fully qualified file names relative to the current directory. /// /// /// Like all other aspects of the WinINet API, this function cannot be safely called from within DllMain or the constructors and /// destructors of global objects. /// /// /// Note WinINet does not support server implementations. In addition, it should not be used from a service. For server /// implementations or services use Microsoft Windows HTTP Services (WinHTTP). /// /// // https://docs.microsoft.com/en-us/windows/win32/api/wininet/nf-wininet-ftpputfilea BOOLAPI FtpPutFileA( HINTERNET hConnect, LPCSTR // lpszLocalFile, LPCSTR lpszNewRemoteFile, DWORD dwFlags, DWORD_PTR dwContext ); [DllImport(Lib.WinInet, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("wininet.h", MSDNShortId = "161d4c04-c928-4178-b75b-f4552ac051ea")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool FtpPutFile(HINTERNET hConnect, string lpszLocalFile, string lpszNewRemoteFile, INTERNET_FLAG dwFlags, [Optional] IntPtr dwContext); /// Removes the specified directory on the FTP server. /// Handle to an FTP session. /// /// Pointer to a null-terminated string that contains the name of the directory to be removed. This can be either a fully qualified /// path or a name relative to the current directory. /// /// /// Returns TRUE if successful, or FALSE otherwise. To get a specific error message, call GetLastError. If the error /// message indicates that the FTP server denied the request to remove a directory, use InternetGetLastResponseInfo to determine why. /// /// /// /// An application should use FtpGetCurrentDirectory to determine the remote site's current working directory, instead of assuming /// that the remote system uses a hierarchical naming scheme for directories. /// /// The lpszDirectory parameter can be either partially or fully qualified file names relative to the current directory. /// /// Like all other aspects of the WinINet API, this function cannot be safely called from within DllMain or the constructors and /// destructors of global objects. /// /// /// Note WinINet does not support server implementations. In addition, it should not be used from a service. For server /// implementations or services use Microsoft Windows HTTP Services (WinHTTP). /// /// // https://docs.microsoft.com/en-us/windows/win32/api/wininet/nf-wininet-ftpremovedirectorya BOOLAPI FtpRemoveDirectoryA( HINTERNET // hConnect, LPCSTR lpszDirectory ); [DllImport(Lib.WinInet, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("wininet.h", MSDNShortId = "4c02af2f-ece8-409a-9c3e-495e1beb80ef")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool FtpRemoveDirectory(HINTERNET hConnect, string lpszDirectory); /// Renames a file stored on the FTP server. /// Handle to an FTP session. /// Pointer to a null-terminated string that contains the name of the file to be renamed. /// Pointer to a null-terminated string that contains the new name for the remote file. /// Returns TRUE if successful, or FALSE otherwise. To get a specific error message, call GetLastError. /// /// /// The lpszExisting and lpszNew parameters can be either partially or fully qualified file names relative to the current directory. /// /// /// Like all other aspects of the WinINet API, this function cannot be safely called from within DllMain or the constructors and /// destructors of global objects. /// /// /// Note WinINet does not support server implementations. In addition, it should not be used from a service. For server /// implementations or services use Microsoft Windows HTTP Services (WinHTTP). /// /// // https://docs.microsoft.com/en-us/windows/win32/api/wininet/nf-wininet-ftprenamefilea BOOLAPI FtpRenameFileA( HINTERNET hConnect, // LPCSTR lpszExisting, LPCSTR lpszNew ); [DllImport(Lib.WinInet, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("wininet.h", MSDNShortId = "2c46d8bb-aceb-4dd2-be4f-2c418357d4ae")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool FtpRenameFile(HINTERNET hConnect, string lpszExisting, string lpszNew); /// Changes to a different working directory on the FTP server. /// Handle to an FTP session. /// /// Pointer to a null-terminated string that contains the name of the directory to become the current working directory. This can be /// either a fully qualified path or a name relative to the current directory. /// /// /// Returns TRUE if successful, or FALSE otherwise. To get a specific error message, call GetLastError. If the error /// message indicates that the FTP server denied the request to change a directory, use InternetGetLastResponseInfo to determine why. /// /// /// /// An application should use FtpGetCurrentDirectory to determine the remote site's current working directory, instead of assuming /// that the remote system uses a hierarchical naming scheme for directories. /// /// The lpszDirectory parameter can be either partially or fully qualified file names relative to the current directory. /// /// Like all other aspects of the WinINet API, this function cannot be safely called from within DllMain or the constructors and /// destructors of global objects. /// /// /// Note WinINet does not support server implementations. In addition, it should not be used from a service. For server /// implementations or services use Microsoft Windows HTTP Services (WinHTTP). /// /// // https://docs.microsoft.com/en-us/windows/win32/api/wininet/nf-wininet-ftpsetcurrentdirectorya BOOLAPI FtpSetCurrentDirectoryA( // HINTERNET hConnect, LPCSTR lpszDirectory ); [DllImport(Lib.WinInet, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("wininet.h", MSDNShortId = "1ee21e9e-d113-427e-ab47-86139e6ecad0")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool FtpSetCurrentDirectory(HINTERNET hConnect, string lpszDirectory); /// Retrieves information about cache configuration. /// /// A pointer to an INTERNET_CACHE_CONFIG_INFO structure that receives information about the cache configuration. The /// dwStructSize field of the structure should be initialized to the size of INTERNET_CACHE_CONFIG_INFO. /// /// This parameter is reserved and must be NULL. /// /// Determines the behavior of the function, as one of the following values. /// /// /// Value /// Meaning /// /// /// CACHE_CONFIG_FORCE_CLEANUP_FC 0x00000020 /// Not used. /// /// /// CACHE_CONFIG_DISK_CACHE_PATHS_FC 0x00000040 /// Not used. /// /// /// CACHE_CONFIG_SYNC_MODE_FC 0x00000080 /// Reserved. /// /// /// CACHE_CONFIG_CONTENT_PATHS_FC 0x00000100 /// /// The CachePath field of the INTERNET_CACHE_CONFIG_INFO structure specified in the lpCachedConfigInfo parameter is filled with a /// pointer to a string identifying the content path. This cannot be used at the same time as CACHE_CONFIG_HISTORY_PATHS_FC or CACHE_CONFIG_COOKIES_PATHS_FC. /// /// /// /// CACHE_CONFIG_HISTORY_PATHS_FC 0x00000400 /// /// The CachePath field of the INTERNET_CACHE_CONFIG_INFO structure specified in the lpCachedConfigInfo parameter is filled with a /// pointer to a string identifying the history path. This cannot be used at the same time as CACHE_CONFIG_CONTENT_PATHS_FC or CACHE_CONFIG_COOKIES_PATHS_FC. /// /// /// /// CACHE_CONFIG_COOKIES_PATHS_FC 0x00000200 /// /// The CachePath field of the INTERNET_CACHE_CONFIG_INFO structure specified in the lpCachedConfigInfo parameter is filled with a /// pointer to a string identifying the cookie path. This cannot be used at the same time as CACHE_CONFIG_CONTENT_PATHS_FC or CACHE_CONFIG_HISTORY_PATHS_FC. /// /// /// /// CACHE_CONFIG_QUOTA_FC 0x00000800 /// /// The dwQuota field of the INTERNET_CACHE_CONFIG_INFO structure specified in the lpCachedConfigInfo is set to the cache limit for /// the container specified in the dwContainer field. /// /// /// /// CACHE_CONFIG_USER_MODE_FC 0x00001000 /// Reserved. /// /// /// CACHE_CONFIG_CONTENT_USAGE_FC 0x00002000 /// /// The dwNormalUsage field of the INTERNET_CACHE_CONFIG_INFO structure specified in the lpCachedConfigInfo is set to the cache size /// for the container specified in the dwContainer field. /// /// /// /// CACHE_CONFIG_STICKY_CONTENT_USAGE_FC 0x00004000 /// /// The dwExemptUsage field of the INTERNET_CACHE_CONFIG_INFO structure specified in the lpCachedConfigInfo is set to the exempt /// usage, the amount of bytes exempt from scavenging, for the container specified in the dwContainer field. (This field must be the /// content container.) /// /// /// /// /// Returns TRUE if successful, or FALSE otherwise. To get extended error information, call GetLastError. /// /// Note WinINet does not support server implementations. In addition, it should not be used from a service. For server /// implementations or services use Microsoft Windows HTTP Services (WinHTTP). /// // https://docs.microsoft.com/en-us/windows/win32/api/winineti/nf-winineti-geturlcacheconfiginfoa BOOLAPI GetUrlCacheConfigInfoA( // LPINTERNET_CACHE_CONFIG_INFOA lpCacheConfigInfo, LPDWORD lpcbCacheConfigInfo, DWORD dwFieldControl ); [DllImport(Lib.WinInet, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("winineti.h", MSDNShortId = "93a29a4f-57bf-497c-a7b1-3960935590f9")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool GetUrlCacheConfigInfo(ref INTERNET_CACHE_CONFIG_INFO lpCacheConfigInfo, [Optional] IntPtr lpcbCacheConfigInfo, CACHE_CONFIG_FC dwFieldControl); /// Retrieves information about a cache entry. /// /// A pointer to a null-terminated string that contains the name of the cache entry. The name string should not contain any escape characters. /// /// /// /// A pointer to an INTERNET_CACHE_ENTRY_INFO structure that receives information about the cache entry. A buffer should be /// allocated for this parameter. /// /// /// Since the required size of the buffer is not known in advance, it is best to allocate a buffer adequate to handle the size of /// most INTERNET_CACHE_ENTRY_INFO entries. There is no cache entry size limit, so applications that need to enumerate the cache /// must be prepared to allocate variable-sized buffers. /// /// /// /// A pointer to a variable that specifies the size of the lpCacheEntryInfo buffer, in bytes. When the function returns, the /// variable contains the number of bytes copied to the buffer, or the required size of the buffer, in bytes. /// /// /// /// Returns TRUE if successful, or FALSE otherwise. To get extended error information, call GetLastError. Possible /// error values include the following. /// /// /// /// Return code /// Description /// /// /// ERROR_FILE_NOT_FOUND /// The specified cache entry is not found in the cache. /// /// /// ERROR_INSUFFICIENT_BUFFER /// /// The size of lpCacheEntryInfo as specified by lpdwCacheEntryInfoBufferSize is not sufficient to contain all the information. The /// value returned in lpdwCacheEntryInfoBufferSize indicates the buffer size necessary to contain all the information. /// /// /// /// /// /// /// GetUrlCacheEntryInfo does not do any URL parsing, so a URL containing an anchor (#) will not be found in the cache, even /// if the resource is cached. For example, if the URL http://example.com/example.htm#sample is passed, the function returns /// ERROR_FILE_NOT_FOUND even if http://example.com/example.htm is in the cache. /// /// /// Like all other aspects of the WinINet API, this function cannot be safely called from within DllMain or the constructors and /// destructors of global objects. /// /// /// Note WinINet does not support server implementations. In addition, it should not be used from a service. For server /// implementations or services use Microsoft Windows HTTP Services (WinHTTP). /// /// // https://docs.microsoft.com/en-us/windows/win32/api/wininet/nf-wininet-geturlcacheentryinfoa BOOLAPI GetUrlCacheEntryInfoA( LPCSTR // lpszUrlName, LPINTERNET_CACHE_ENTRY_INFOA lpCacheEntryInfo, LPDWORD lpcbCacheEntryInfo ); [DllImport(Lib.WinInet, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("wininet.h", MSDNShortId = "0f70bcef-2d56-4765-a44e-4549b4ae2ced")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool GetUrlCacheEntryInfo(string lpszUrlName, IntPtr lpCacheEntryInfo, ref uint lpcbCacheEntryInfo); /// /// Retrieves information on the cache entry associated with the specified URL, taking into account any redirections that are /// applied in offline mode by the HttpSendRequest function. /// /// /// A pointer to a null-terminated string that contains the name of the cache entry. The name string should not contain any /// escape characters. /// /// /// /// A pointer to an INTERNET_CACHE_ENTRY_INFO structure that receives information about the cache entry. A buffer should be /// allocated for this parameter. /// /// /// Since the required size of the buffer is not known in advance, it is best to allocate a buffer adequate to handle the size of /// most INTERNET_CACHE_ENTRY_INFO entries. There is no cache entry size limit, so applications that need to enumerate the cache /// must be prepared to allocate variable-sized buffers. /// /// /// /// Pointer to a variable that specifies the size of the lpCacheEntryInfo buffer, in bytes. When the function returns, the variable /// contains the number of bytes copied to the buffer, or the required size of the buffer in bytes. /// /// This parameter is reserved and must be NULL. /// This parameter is reserved and must be NULL. /// This parameter is reserved and must be NULL. /// This parameter is reserved and must be 0. /// /// /// Returns TRUE if the URL was located, or FALSE otherwise. Call GetLastError for specific error information. /// Possible errors include the following. /// /// /// /// Return code /// Description /// /// /// ERROR_FILE_NOT_FOUND /// The URL was not found in the cache index, even after taking any cached redirections into account. /// /// /// ERROR_INSUFFICIENT_BUFFER /// /// The buffer referenced by lpCacheEntryInfo was not large enough to hold the requested information. The size of the buffer needed /// will be returned to lpdwCacheEntryInfoBufSize. /// /// /// /// /// /// /// GetUrlCacheEntryInfoEx does not do any URL parsing, so a URL containing an anchor (#) will not be found in the cache, /// even if the resource is cached. For example, if the URL http://example.com/example.htm#sample is passed, the function returns /// ERROR_FILE_NOT_FOUND even if http://example.com/example.htm is in the cache. /// /// /// Like all other aspects of the WinINet API, this function cannot be safely called from within DllMain or the constructors and /// destructors of global objects. /// /// /// Note WinINet does not support server implementations. In addition, it should not be used from a service. For server /// implementations or services use Microsoft Windows HTTP Services (WinHTTP). /// /// // https://docs.microsoft.com/en-us/windows/win32/api/wininet/nf-wininet-geturlcacheentryinfoexa BOOLAPI GetUrlCacheEntryInfoExA( // LPCSTR lpszUrl, LPINTERNET_CACHE_ENTRY_INFOA lpCacheEntryInfo, LPDWORD lpcbCacheEntryInfo, LPSTR lpszRedirectUrl, LPDWORD // lpcbRedirectUrl, LPVOID lpReserved, DWORD dwFlags ); [DllImport(Lib.WinInet, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("wininet.h", MSDNShortId = "3842dae9-9474-492a-83fa-29d7927dc92d")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool GetUrlCacheEntryInfoEx(string lpszUrl, IntPtr lpCacheEntryInfo, ref uint lpcbCacheEntryInfo, [Optional] IntPtr lpszRedirectUrl, [Optional] IntPtr lpcbRedirectUrl, [Optional] IntPtr lpReserved, [Optional] uint dwFlags); /// /// [The GopherCreateLocator function is available for use in the operating systems specified in the Requirements section.] /// Creates a Gopher or Gopher+ locator string from the selector string's component parts. /// /// /// Pointer to a null-terminated string that contains the name of the host, or a dotted-decimal IP address (such as 198.105.232.1). /// /// /// Port number on which the Gopher server at lpszHost lives, in host byte order. If nServerPort is /// INTERNET_INVALID_PORT_NUMBER, the default Gopher port is used. /// /// /// Pointer to a null-terminated string that contains the Gopher document or directory to be displayed. If this parameter is /// NULL, the function returns the default directory for the Gopher server. /// /// /// Pointer to the selector string to send to the Gopher server in order to retrieve information. This parameter can be NULL. /// /// /// Determines whether lpszSelectorString refers to a directory or document, and whether the request is Gopher+ or Gopher. The /// default value, GOPHER_TYPE_DIRECTORY, is used if the value of dwGopherType is zero. This can be one of the gopher type values. /// /// /// Pointer to a buffer that receives the locator string. If lpszLocator is NULL, lpdwBufferLength receives the necessary /// buffer length, but the function performs no other processing. /// /// /// Pointer to a variable that contains the length of the lpszLocator buffer, in characters. When the function returns, this /// parameter receives the number of characters written to the buffer. If GetLastError returns ERROR_INSUFFICIENT_BUFFER, /// this parameter receives the number of characters required. /// /// /// Returns TRUE if successful, or FALSE otherwise. To get extended error information, call GetLastError or InternetGetLastResponseInfo. /// /// /// To retrieve information from a Gopher server, an application must first get a Gopher "locator" from the Gopher server. /// /// The locator, which the application should treat as an opaque token, is normally used for calls to the GopherFindFirstFile /// function to retrieve a specific piece of information. /// /// /// Like all other aspects of the WinINet API, this function cannot be safely called from within DllMain or the constructors and /// destructors of global objects. /// /// /// Note WinINet does not support server implementations. In addition, it should not be used from a service. For server /// implementations or services use Microsoft Windows HTTP Services (WinHTTP). /// /// // https://docs.microsoft.com/en-us/windows/win32/api/wininet/nf-wininet-gophercreatelocatora BOOLAPI GopherCreateLocatorA( LPCSTR // lpszHost, INTERNET_PORT nServerPort, LPCSTR lpszDisplayString, LPCSTR lpszSelectorString, DWORD dwGopherType, LPSTR lpszLocator, // LPDWORD lpdwBufferLength ); [DllImport(Lib.WinInet, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("wininet.h", MSDNShortId = "972a4ff9-efda-4784-9ac8-c76e679e8032")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool GopherCreateLocator(string lpszHost, INTERNET_PORT nServerPort, [Optional] string lpszDisplayString, [Optional] string lpszSelectorString, GOPHER_TYPE dwGopherType, [Optional] StringBuilder lpszLocator, ref uint lpdwBufferLength); /// /// [The GopherFindFirstFile function is available for use in the operating systems specified in the Requirements section.] /// /// Uses a Gopher locator and search criteria to create a session with the server and locate the requested documents, binary files, /// index servers, or directory trees. /// /// /// Handle to a Gopher session returned by InternetConnect. /// /// Pointer to a null-terminated string that contains the name of the item to locate. This can be one of the following: /// /// /// Gopher locator returned by a previous call to this function or the InternetFindNextFile function. /// /// /// NULL pointer or empty string indicating that the topmost information from a Gopher server is being returned. /// /// /// Locator created by the GopherCreateLocator function. /// /// /// /// /// Pointer to a buffer that contains the strings to search, if this request is to an index server. Otherwise, this parameter should /// be NULL. /// /// Pointer to a GOPHER_FIND_DATA structure that receives the information retrieved by this function. /// /// Controls the function behavior. This parameter can be a combination of the following values. /// /// /// Value /// Meaning /// /// /// INTERNET_FLAG_HYPERLINK /// /// Forces a reload if there was no Expires time and no LastModified time returned from the server when determining whether to /// reload the item from the network. /// /// /// /// INTERNET_FLAG_NEED_FILE /// Causes a temporary file to be created if the file cannot be cached. /// /// /// INTERNET_FLAG_NO_CACHE_WRITE /// Does not add the returned entity to the cache. /// /// /// INTERNET_FLAG_RELOAD /// Forces a download of the requested file, object, or directory listing from the origin server, not from the cache. /// /// /// INTERNET_FLAG_RESYNCHRONIZE /// /// Reloads HTTP resources if the resource has been modified since the last time it was downloaded. All FTP and Gopher resources are reloaded. /// /// /// /// /// /// Pointer to a variable that contains the application-defined value that associates this search with any application data. /// /// /// Returns a valid search handle if successful, or NULL otherwise. To retrieve extended error information, call GetLastError /// or InternetGetLastResponseInfo. /// /// /// /// GopherFindFirstFile closely resembles the FindFirstFile function. It creates a connection with a Gopher server, and then /// returns a single structure containing information about the first Gopher object referenced by the locator string. /// /// /// After calling GopherFindFirstFile to retrieve the first Gopher object in an enumeration, an application can use the /// InternetFindNextFile function to retrieve subsequent Gopher objects. /// /// /// After the calling application has finished using the HINTERNET handle returned by GopherFindFirstFile, it must be closed /// using the InternetCloseHandle function. /// /// /// Like all other aspects of the WinINet API, this function cannot be safely called from within DllMain or the constructors and /// destructors of global objects. /// /// /// Note WinINet does not support server implementations. In addition, it should not be used from a service. For server /// implementations or services use Microsoft Windows HTTP Services (WinHTTP). /// /// // https://docs.microsoft.com/en-us/windows/win32/api/wininet/nf-wininet-gopherfindfirstfilea void GopherFindFirstFileA( HINTERNET // hConnect, LPCSTR lpszLocator, LPCSTR lpszSearchString, LPGOPHER_FIND_DATAA lpFindData, DWORD dwFlags, DWORD_PTR dwContext ); [DllImport(Lib.WinInet, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("wininet.h", MSDNShortId = "801dc601-9d1d-4f7d-acf0-b36ea2314d70")] public static extern SafeHINTERNET GopherFindFirstFile(HINTERNET hConnect, [Optional] string lpszLocator, [Optional] string lpszSearchString, out GOPHER_FIND_DATA lpFindData, INTERNET_FLAG dwFlags, [Optional] IntPtr dwContext); /// /// [The GopherGetAttribute function is available for use in the operating systems specified in the Requirements section.] /// Retrieves the specific attribute information from the server. /// /// Handle to a Gopher session returned by InternetConnect. /// /// Pointer to a null-terminated string that identifies the item at the Gopher server on which to return attribute information. /// /// /// Pointer to a space-delimited string specifying the names of attributes to return. If lpszAttributeName is NULL, /// GopherGetAttribute returns information about all attributes. /// /// Pointer to an application-defined buffer from which attribute information is retrieved. /// Size of the lpBuffer buffer, in TCHARs. /// Pointer to a variable that contains the number of characters read into the lpBuffer buffer. /// /// /// Pointer to a GopherAttributeEnumerator callback function that enumerates each attribute of the locator. This parameter is /// optional. If it is NULL, all Gopher attribute information is placed into lpBuffer. If lpfnEnumerator is specified, the /// callback function is called once for each attribute of the object. /// /// /// The callback function receives the address of a single GOPHER_ATTRIBUTE_TYPE structure with each call. The enumeration callback /// function allows the application to avoid having to parse the Gopher attribute information. /// /// /// Application-defined value that associates this operation with any application data. /// /// Returns TRUE if the request is satisfied, or FALSE otherwise. To get extended error information, call GetLastError /// or InternetGetLastResponseInfo. /// /// /// Generally, applications call this function after calling GopherFindFirstFile or InternetFindNextFile. /// The size of the lpBuffer parameter must be equal to or greater than the value of MIN_GOPHER_ATTRIBUTE_LENGTH. /// /// Like all other aspects of the WinINet API, this function cannot be safely called from within DllMain or the constructors and /// destructors of global objects. /// /// /// Note WinINet does not support server implementations. In addition, it should not be used from a service. For server /// implementations or services use Microsoft Windows HTTP Services (WinHTTP). /// /// // https://docs.microsoft.com/en-us/windows/win32/api/wininet/nf-wininet-gophergetattributea BOOLAPI GopherGetAttributeA( HINTERNET // hConnect, LPCSTR lpszLocator, LPCSTR lpszAttributeName, LPBYTE lpBuffer, DWORD dwBufferLength, LPDWORD lpdwCharactersReturned, // GOPHER_ATTRIBUTE_ENUMERATOR lpfnEnumerator, DWORD_PTR dwContext ); [DllImport(Lib.WinInet, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("wininet.h", MSDNShortId = "c9e95532-8c65-45fb-acd0-a1f09cee2ce2")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool GopherGetAttribute(HINTERNET hConnect, string lpszLocator, [Optional] string lpszAttributeName, IntPtr lpBuffer, uint dwBufferLength, out uint lpdwCharactersReturned, [Optional] GopherAttributeEnumerator lpfnEnumerator, [Optional] IntPtr dwContext); /// /// /// [The GopherGetLocatorType function is available for use in the operating systems specified in the Requirements section.] /// /// Parses a Gopher locator and determines its attributes. /// /// Pointer to a null-terminated string that specifies the Gopher locator to be parsed. /// /// Pointer to a variable that receives the type of the locator. The type is a bitmask that consists of a combination of the gopher /// type values. /// /// Returns TRUE if successful, or FALSE otherwise. To get extended error information, call GetLastError. /// /// /// GopherGetLocatorType returns information about the item referenced by a Gopher locator. Note that it is possible for /// multiple attributes to be set on a file. For example, both GOPHER_TYPE_TEXT_FILE and GOPHER_TYPE_GOPHER_PLUS are /// set for a text file stored on a Gopher+ server. /// /// /// Like all other aspects of the WinINet API, this function cannot be safely called from within DllMain or the constructors and /// destructors of global objects. /// /// /// Note WinINet does not support server implementations. In addition, it should not be used from a service. For server /// implementations or services use Microsoft Windows HTTP Services (WinHTTP). /// /// // https://docs.microsoft.com/en-us/windows/win32/api/wininet/nf-wininet-gophergetlocatortypea BOOLAPI GopherGetLocatorTypeA( LPCSTR // lpszLocator, LPDWORD lpdwGopherType ); [DllImport(Lib.WinInet, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("wininet.h", MSDNShortId = "e6f0ef67-c411-43ff-a477-5a8635057f2c")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool GopherGetLocatorType(string lpszLocator, out GOPHER_TYPE lpdwGopherType); /// /// [The GopherOpenFile function is available for use in the operating systems specified in the Requirements section.] /// Begins reading a Gopher data file from a Gopher server. /// /// Handle to a Gopher session returned by InternetConnect. /// /// Pointer to a null-terminated string that specifies the file to be opened. Generally, this locator is returned from a call /// to GopherFindFirstFile or InternetFindNextFile. Because the Gopher protocol has no concept of a current directory, the locator /// is always fully qualified. /// /// /// Pointer to a null-terminated string that describes the view to open if several views of the file exist on the server. If /// lpszView is NULL, the function uses the default file view. /// /// /// Conditions under which subsequent transfers occur. This parameter can be any of the following values. /// /// /// Value /// Meaning /// /// /// INTERNET_FLAG_HYPERLINK /// /// Forces a reload if there was no Expires time and no LastModified time returned from the server when determining whether to /// reload the item from the network. /// /// /// /// INTERNET_FLAG_NEED_FILE /// Causes a temporary file to be created if the file cannot be cached. /// /// /// INTERNET_FLAG_NO_CACHE_WRITE /// Does not add the returned entity to the cache. /// /// /// INTERNET_FLAG_RELOAD /// Forces a download of the requested file, object, or directory listing from the origin server, not from the cache. /// /// /// INTERNET_FLAG_RESYNCHRONIZE /// /// Reloads HTTP resources if the resource has been modified since the last time it was downloaded. All FTP and Gopher resources are reloaded. /// /// /// /// /// /// Pointer to a variable that contains an application-defined value that associates this operation with any application data. /// /// /// Returns a handle if successful, or NULL if the file cannot be opened. To retrieve extended error information, call /// GetLastError or InternetGetLastResponseInfo. /// /// /// /// GopherOpenFile opens a file at a Gopher server. Because a file cannot actually be opened or locked at a server, this /// function simply associates location information with a handle that an application can use for file-based operations such as /// InternetReadFile or GopherGetAttribute. /// /// /// After the calling application has finished using the HINTERNET handle returned by GopherOpenFile, it must be closed using /// the InternetCloseHandle function. /// /// /// Like all other aspects of the WinINet API, this function cannot be safely called from within DllMain or the constructors and /// destructors of global objects. /// /// /// Note WinINet does not support server implementations. In addition, it should not be used from a service. For server /// implementations or services use Microsoft Windows HTTP Services (WinHTTP). /// /// // https://docs.microsoft.com/en-us/windows/win32/api/wininet/nf-wininet-gopheropenfilea void GopherOpenFileA( HINTERNET hConnect, // LPCSTR lpszLocator, LPCSTR lpszView, DWORD dwFlags, DWORD_PTR dwContext ); [DllImport(Lib.WinInet, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("wininet.h", MSDNShortId = "2731d573-f981-48ce-a306-bb7e295cefc6")] public static extern SafeHINTERNET GopherOpenFile(HINTERNET hConnect, string lpszLocator, [Optional] string lpszView, INTERNET_FLAG dwFlags, [Optional] IntPtr dwContext); /// Adds one or more HTTP request headers to the HTTP request handle. /// A handle returned by a call to the HttpOpenRequest function. /// /// A pointer to a string variable containing the headers to append to the request. Each header must be terminated by a CR/LF /// (carriage return/line feed) pair. /// /// /// The size of lpszHeaders, in TCHARs. If this parameter is -1L, the function assumes that lpszHeaders is zero-terminated /// (ASCIIZ), and the length is computed. /// /// /// A set of modifiers that control the semantics of this function. This parameter can be a combination of the following values. /// /// /// Value /// Meaning /// /// /// HTTP_ADDREQ_FLAG_ADD /// Adds the header if it does not exist. Used with HTTP_ADDREQ_FLAG_REPLACE. /// /// /// HTTP_ADDREQ_FLAG_ADD_IF_NEW /// Adds the header only if it does not already exist; otherwise, an error is returned. /// /// /// HTTP_ADDREQ_FLAG_COALESCE /// Coalesces headers of the same name. /// /// /// HTTP_ADDREQ_FLAG_COALESCE_WITH_COMMA /// /// Coalesces headers of the same name. For example, adding "Accept: text/*" followed by "Accept: audio/*" with this flag results in /// the formation of the single header "Accept: text/*, audio/*". This causes the first header found to be coalesced. It is up to /// the calling application to ensure a cohesive scheme with respect to coalesced/separate headers. /// /// /// /// HTTP_ADDREQ_FLAG_COALESCE_WITH_SEMICOLON /// Coalesces headers of the same name using a semicolon. /// /// /// HTTP_ADDREQ_FLAG_REPLACE /// /// Replaces or removes a header. If the header value is empty and the header is found, it is removed. If not empty, the header /// value is replaced. /// /// /// /// /// Returns TRUE if successful, or FALSE otherwise. To get extended error information, call GetLastError. /// /// /// HttpAddRequestHeaders appends additional, free-format headers to the HTTP request handle and is intended for use by /// sophisticated clients that need detailed control over the exact request sent to the HTTP server. /// /// /// Note that for basic HttpAddRequestHeaders, the application can pass in multiple headers in a single buffer. If the /// application is trying to remove or replace a header, only one header can be supplied in lpszHeaders. /// /// /// Note The HttpAddRequestHeadersA function represents headers as ISO-8859-1 characters not ANSI characters. The /// HttpAddRequestHeadersW function represents headers as ISO-8859-1 characters converted to UTF-16LE characters. As a /// result, it is never safe to use the HttpAddRequestHeadersW function when the headers to be added can contain non-ASCII /// characters. Instead, an application can use the MultiByteToWideChar and WideCharToMultiByte functions with a Codepage parameter /// set to 28591 to map between ANSI characters and UTF-16LE characters. /// /// /// Like all other aspects of the WinINet API, this function cannot be safely called from within DllMain or the constructors and /// destructors of global objects. /// /// /// Note WinINet does not support server implementations. In addition, it should not be used from a service. For server /// implementations or services use Microsoft Windows HTTP Services (WinHTTP). /// /// // https://docs.microsoft.com/en-us/windows/win32/api/wininet/nf-wininet-httpaddrequestheadersa BOOLAPI HttpAddRequestHeadersA( // HINTERNET hRequest, LPCSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwModifiers ); [DllImport(Lib.WinInet, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("wininet.h", MSDNShortId = "636c3442-a2e6-4885-8fb4-1f6996ba6860")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool HttpAddRequestHeaders(HINTERNET hRequest, string lpszHeaders, int dwHeadersLength, HTTP_ADDREQ_FLAG dwModifiers); /// Ends an HTTP request that was initiated by HttpSendRequestEx. /// Handle returned by HttpOpenRequest and sent by HttpSendRequestEx. /// This parameter is reserved and must be NULL. /// This parameter is reserved and must be set to 0. /// This parameter is reserved and must be set to 0. /// /// If the function succeeds, the function returns TRUE. /// If the function fails, it returns FALSE. To get extended error information, call GetLastError. /// /// /// If lpBuffersOut is not set to NULL, HttpEndRequest will return ERROR_INVALID_PARAMETER. /// /// Like all other aspects of the WinINet API, this function cannot be safely called from within DllMain or the constructors and /// destructors of global objects. /// /// /// Note WinINet does not support server implementations. In addition, it should not be used from a service. For server /// implementations or services use Microsoft Windows HTTP Services (WinHTTP). /// /// // https://docs.microsoft.com/en-us/windows/win32/api/wininet/nf-wininet-httpendrequesta BOOLAPI HttpEndRequestA( HINTERNET // hRequest, LPINTERNET_BUFFERSA lpBuffersOut, DWORD dwFlags, DWORD_PTR dwContext ); [DllImport(Lib.WinInet, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("wininet.h", MSDNShortId = "6ea91da6-0bc2-49b6-a56b-c4224ad73b81")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool HttpEndRequest(HINTERNET hRequest, IntPtr lpBuffersOut = default, uint dwFlags = 0, IntPtr dwContext = default); /// Creates an HTTP request handle. /// A handle to an HTTP session returned by InternetConnect. /// /// A pointer to a null-terminated string that contains the HTTP verb to use in the request. If this parameter is /// NULL, the function uses GET as the HTTP verb. /// /// /// A pointer to a null-terminated string that contains the name of the target object of the specified HTTP verb. This is /// generally a file name, an executable module, or a search specifier. /// /// /// /// A pointer to a null-terminated string that contains the HTTP version to use in the request. Settings in Internet Explorer /// will override the value specified in this parameter. /// /// /// If this parameter is NULL, the function uses an HTTP version of 1.1 or 1.0, depending on the value of the Internet /// Explorer settings. /// /// /// /// Value /// Meaning /// /// /// HTTP/1.0 /// HTTP version 1.0 /// /// /// HTTP/1.1 /// HTTP version 1.1 /// /// /// /// /// A pointer to a null-terminated string that specifies the URL of the document from which the URL in the request /// (lpszObjectName) was obtained. If this parameter is NULL, no referrer is specified. /// /// /// An array of strings that indicates media types accepted by the client. /// /// If this parameter is NULL, no types are accepted by the client. Servers generally interpret a lack of accept types to /// indicate that the client accepts only documents of type "text/*" (that is, only text documents—no pictures or other binary /// files). For more information and a list of valid media types, see ftp://ftp.isi.edu/in-notes/iana/assignments/media-types/media-types. /// /// /// /// Internet options. This parameter can be any of the following values. /// /// /// Value /// Meaning /// /// /// INTERNET_FLAG_CACHE_IF_NET_FAIL /// /// Returns the resource from the cache if the network request for the resource fails due to an ERROR_INTERNET_CONNECTION_RESET (the /// connection with the server has been reset) or ERROR_INTERNET_CANNOT_CONNECT (the attempt to connect to the server failed). /// /// /// /// INTERNET_FLAG_HYPERLINK /// /// Forces a reload if there was no Expires time and no LastModified time returned from the server when determining whether to /// reload the item from the network. /// /// /// /// INTERNET_FLAG_IGNORE_CERT_CN_INVALID /// /// Disables checking of SSL/PCT-based certificates that are returned from the server against the host name given in the request. /// WinINet functions use a simple check against certificates by comparing for matching host names and simple wildcarding rules. /// /// /// /// INTERNET_FLAG_IGNORE_CERT_DATE_INVALID /// Disables checking of SSL/PCT-based certificates for proper validity dates. /// /// /// INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTP /// /// Disables detection of this special type of redirect. When this flag is used, WinINet functions transparently allow redirects /// from HTTPS to HTTP URLs. /// /// /// /// INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTPS /// /// Disables detection of this special type of redirect. When this flag is used, WinINet functions transparently allow redirects /// from HTTP to HTTPS URLs. /// /// /// /// INTERNET_FLAG_KEEP_CONNECTION /// /// Uses keep-alive semantics, if available, for the connection. This flag is required for Microsoft Network (MSN), NT LAN Manager /// (NTLM), and other types of authentication. /// /// /// /// INTERNET_FLAG_NEED_FILE /// Causes a temporary file to be created if the file cannot be cached. /// /// /// INTERNET_FLAG_NO_AUTH /// Does not attempt authentication automatically. /// /// /// INTERNET_FLAG_NO_AUTO_REDIRECT /// Does not automatically handle redirection in HttpSendRequest. /// /// /// INTERNET_FLAG_NO_CACHE_WRITE /// Does not add the returned entity to the cache. /// /// /// INTERNET_FLAG_NO_COOKIES /// /// Does not automatically add cookie headers to requests, and does not automatically add returned cookies to the cookie database. /// /// /// /// INTERNET_FLAG_NO_UI /// Disables the cookie dialog box. /// /// /// INTERNET_FLAG_PRAGMA_NOCACHE /// Forces the request to be resolved by the origin server, even if a cached copy exists on the proxy. /// /// /// INTERNET_FLAG_RELOAD /// /// Forces a download of the requested file, object, or directory listing from the origin server, not from the cache. /// /// /// /// INTERNET_FLAG_RESYNCHRONIZE /// /// Reloads HTTP resources if the resource has been modified since the last time it was downloaded. All FTP resources are reloaded. /// Windows XP and Windows Server 2003 R2 and earlier: Gopher resources are also reloaded. /// /// /// /// INTERNET_FLAG_SECURE /// /// Uses secure transaction semantics. This translates to using Secure Sockets Layer/Private Communications Technology (SSL/PCT) and /// is only meaningful in HTTP requests. /// /// /// /// /// /// A pointer to a variable that contains the application-defined value that associates this operation with any application data. /// /// /// Returns an HTTP request handle if successful, or NULL otherwise. To retrieve extended error information, call GetLastError. /// /// /// /// The HttpOpenRequest function creates a new HTTP request handle and stores the specified parameters in that handle. An /// HTTP request handle holds a request to be sent to an HTTP server and contains all RFC822/MIME/HTTP headers to be sent as part of /// the request. /// /// /// If a verb other than "GET" or "POST" is specified, HttpOpenRequest automatically sets INTERNET_FLAG_NO_CACHE_WRITE and /// INTERNET_FLAG_RELOAD for the request. /// /// /// With Microsoft Internet Explorer 5 and later, if lpszVerb is set to "HEAD", the Content-Length header is ignored on responses /// from HTTP/1.1 servers. /// /// /// On Windows 7, Windows Server 2008 R2, and later, the lpszVersion parameter is overridden by Internet Explorer settings. The /// EnableHttp1_1 is a registry value under HKLM\Software\Microsoft\InternetExplorer\AdvacnedOptions\HTTP\GENABLE /// controlled by Internet Options set in Internet Explorer for the system. The EnableHttp1_1 value defaults to 1. The /// HttpOpenRequest function upgrades any HTTP version less than 1.1 to HTTP version 1.1 if EnableHttp1_1 is set to 1. /// /// /// After the calling application has finished using the HINTERNET handle returned by HttpOpenRequest, it must be closed /// using the InternetCloseHandle function. /// /// /// Note When a request is sent in asynchronous mode (the dwFlags parameter of InternetOpen specifies /// INTERNET_FLAG_ASYNC), and the dwContext parameter is zero ( INTERNET_NO_CALLBACK), the callback function set with /// InternetSetStatusCallback on the request handle will not be invoked, however, the call will still be performed in asynchronous mode. /// /// /// Like all other aspects of the WinINet API, this function cannot be safely called from within DllMain or the constructors and /// destructors of global objects. /// /// /// Note WinINet does not support server implementations. In addition, it should not be used from a service. For server /// implementations or services use Microsoft Windows HTTP Services (WinHTTP). /// /// // https://docs.microsoft.com/en-us/windows/win32/api/wininet/nf-wininet-httpopenrequesta void HttpOpenRequestA( HINTERNET hConnect, // LPCSTR lpszVerb, LPCSTR lpszObjectName, LPCSTR lpszVersion, LPCSTR lpszReferrer, LPCSTR *lplpszAcceptTypes, DWORD dwFlags, // DWORD_PTR dwContext ); [DllImport(Lib.WinInet, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("wininet.h", MSDNShortId = "caaff8e8-7db9-4d6d-8ba2-d8d19475173a")] public static extern SafeHINTERNET HttpOpenRequest(HINTERNET hConnect, [Optional] string lpszVerb, string lpszObjectName, [Optional] string lpszVersion, [Optional] string lpszReferrer, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(StringPtrArrayMarshaler), MarshalCookie = "Auto"), Optional] string[] lplpszAcceptTypes, [Optional] INTERNET_FLAG dwFlags, [Optional] IntPtr dwContext); /// Retrieves header information associated with an HTTP request. /// A handle returned by a call to the HttpOpenRequest or InternetOpenUrl function. /// /// A combination of an attribute to be retrieved and flags that modify the request. For a list of possible attribute and modifier /// values, see Query Info Flags. /// /// A pointer to a buffer to receive the requested information. This parameter must not be NULL. /// /// A pointer to a variable that contains, on entry, the size in bytes of the buffer pointed to by lpvBuffer. /// /// When the function returns successfully, this variable contains the number of bytes of information written to the buffer. In the /// case of a string, the byte count does not include the string's terminating null character. /// /// /// When the function fails with an extended error code of ERROR_INSUFFICIENT_BUFFER, the variable pointed to by /// lpdwBufferLength contains on exit the size, in bytes, of a buffer large enough to receive the requested information. The calling /// application can then allocate a buffer of this size or larger, and call the function again. /// /// /// /// A pointer to a zero-based header index used to enumerate multiple headers with the same name. When calling the function, this /// parameter is the index of the specified header to return. When the function returns, this parameter is the index of the next /// header. If the next index cannot be found, ERROR_HTTP_HEADER_NOT_FOUND is returned. /// /// Returns TRUE if successful, or FALSE otherwise. To get extended error information, call GetLastError. /// /// You can retrieve the following types of data from HttpQueryInfo: /// /// /// Strings (default) /// /// /// SYSTEMTIME (for dates) /// /// /// DWORD (for STATUS_CODE, CONTENT_LENGTH, and so on, if HTTP_QUERY_FLAG_NUMBER has been used) /// /// /// /// If your application requires that the data be returned as a data type other than a string, you must include the appropriate /// modifier with the attribute passed to dwInfoLevel. /// /// /// The HttpQueryInfo function is available in Microsoft Internet Explorer 3.0 for ISO-8859-1 characters ( /// HttpQueryInfoA function) and in Internet Explorer 4.0 or later for ISO-8859-1 characters ( HttpQueryInfoA /// function) and for ISO-8859-1 characters converted to UTF-16LE characters.(the HttpQueryInfoW function). /// /// /// Note The HttpQueryInfoA function represents headers as ISO-8859-1 characters not ANSI characters. The /// HttpQueryInfoW function represents headers as ISO-8859-1 characters converted to UTF-16LE characters. As a result, it is /// never safe to use the HttpQueryInfoW function when the headers can contain non-ASCII characters. Instead, an application /// can use the MultiByteToWideChar and WideCharToMultiByte functions with a Codepage parameter set to 28591 to map between ANSI /// characters and UTF-16LE characters. /// /// See Retrieving HTTP Headers for an example code calling the HttpQueryInfo function. /// /// Like all other aspects of the WinINet API, this function cannot be safely called from within DllMain or the constructors and /// destructors of global objects. /// /// /// Note WinINet does not support server implementations. In addition, it should not be used from a service. For server /// implementations or services use Microsoft Windows HTTP Services (WinHTTP). /// /// // https://docs.microsoft.com/en-us/windows/win32/api/wininet/nf-wininet-httpqueryinfoa BOOLAPI HttpQueryInfoA( HINTERNET hRequest, // DWORD dwInfoLevel, LPVOID lpBuffer, LPDWORD lpdwBufferLength, LPDWORD lpdwIndex ); [DllImport(Lib.WinInet, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("wininet.h", MSDNShortId = "5747ce19-5004-4eea-abe9-dd00abac1b3b")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool HttpQueryInfo(HINTERNET hRequest, HTTP_QUERY dwInfoLevel, IntPtr lpBuffer, ref uint lpdwBufferLength, ref uint lpdwIndex); /// Retrieves header information associated with an HTTP request. /// A handle returned by a call to the HttpOpenRequest or InternetOpenUrl function. /// /// A combination of an attribute to be retrieved and flags that modify the request. For a list of possible attribute and modifier /// values, see Query Info Flags. /// /// /// A pointer to a zero-based header index used to enumerate multiple headers with the same name. When calling the function, this /// parameter is the index of the specified header to return. When the function returns, this parameter is the index of the next /// header. If the next index cannot be found, ERROR_HTTP_HEADER_NOT_FOUND is returned. /// /// /// A instance with sufficient memory needed to hold the response. This should be cast to the type required. /// public static ISafeMemoryHandle HttpQueryInfo(HINTERNET hRequest, HTTP_QUERY dwInfoLevel, ref uint lpdwIndex) { var sz = 0U; HttpQueryInfo(hRequest, dwInfoLevel, IntPtr.Zero, ref sz, ref lpdwIndex); var err = Win32Error.GetLastError(); if (err != Win32Error.ERROR_INSUFFICIENT_BUFFER) err.ThrowIfFailed(); var hMem = new SafeCoTaskMemHandle(sz); var res = HttpQueryInfo(hRequest, dwInfoLevel, hMem, ref sz, ref lpdwIndex); if (!res) Win32Error.ThrowLastError(); return hMem; } /// Retrieves header information associated with an HTTP request. /// /// Return type. This should be, by default, a unless one of the return type modification flags is passed into /// . /// /// A handle returned by a call to the HttpOpenRequest or InternetOpenUrl function. /// /// A combination of an attribute to be retrieved and flags that modify the request. For a list of possible attribute and modifier /// values, see Query Info Flags. /// /// /// A pointer to a zero-based header index used to enumerate multiple headers with the same name. When calling the function, this /// parameter is the index of the specified header to return. When the function returns, this parameter is the index of the next /// header. If the next index cannot be found, ERROR_HTTP_HEADER_NOT_FOUND is returned. /// /// The HTTP information. public static T HttpQueryInfo(HINTERNET hRequest, HTTP_QUERY dwInfoLevel, ref uint lpdwIndex) { using (var hMem = HttpQueryInfo(hRequest, dwInfoLevel, ref lpdwIndex)) return typeof(T) == typeof(string) ? (T)(object)hMem.ToString(-1) : (typeof(T) == typeof(bool) ? (T)(object)Convert.ToBoolean(hMem.ToStructure()) : hMem.ToStructure()); } /// /// Sends the specified request to the HTTP server, allowing callers to send extra data beyond what is normally passed to HttpSendRequestEx. /// /// A handle returned by a call to the HttpOpenRequest function. /// /// A pointer to a null-terminated string that contains the additional headers to be appended to the request. This parameter /// can be NULL if there are no additional headers to be appended. /// /// /// The size of the additional headers, in TCHARs. If this parameter is -1L and lpszHeaders is not NULL, the function /// assumes that lpszHeaders is zero-terminated (ASCIIZ), and the length is calculated. See Remarks for specifics. /// /// /// A pointer to a buffer containing any optional data to be sent immediately after the request headers. This parameter is generally /// used for POST and PUT operations. The optional data can be the resource or information being posted to the server. This /// parameter can be NULL if there is no optional data to send. /// /// /// The size of the optional data, in bytes. This parameter can be zero if there is no optional data to send. /// /// Returns TRUE if successful, or FALSE otherwise. To get extended error information, call GetLastError. /// /// /// HttpSendRequest sends the specified request to the HTTP server and allows the client to specify additional headers to /// send along with the request. /// /// /// The function also lets the client specify optional data to send to the HTTP server immediately following the request headers. /// This feature is generally used for "write" operations such as PUT and POST. /// /// /// After the request is sent, the status code and response headers from the HTTP server are read. These headers are maintained /// internally and are available to client applications through the HttpQueryInfo function. /// /// /// An application can use the same HTTP request handle in multiple calls to HttpSendRequest, but the application must read /// all data returned from the previous call before calling the function again. /// /// /// In offline mode, HttpSendRequest returns ERROR_FILE_NOT_FOUND if the resource is not found in the Internet cache. /// /// /// There two versions of HttpSendRequestHttpSendRequestA (used with ANSI builds) and HttpSendRequestW (used /// with Unicode builds). If dwHeadersLength is -1L and lpszHeaders is not NULL, the following will happen: If /// HttpSendRequestA is called, the function assumes that lpszHeaders is zero-terminated (ASCIIZ), and the length is /// calculated. If HttpSendRequestW is called, the function fails with ERROR_INVALID_PARAMETER. /// /// /// Note The HttpSendRequestA function represents headers as ISO-8859-1 characters not ANSI characters. The /// HttpSendRequestW function represents headers as ISO-8859-1 characters converted to UTF-16LE characters. As a result, it /// is never safe to use the HttpSendRequestW function when the headers to be added can contain non-ASCII characters. /// Instead, an application can use the MultiByteToWideChar and WideCharToMultiByte functions with a Codepage parameter set to 28591 /// to map between ANSI characters and UTF-16LE characters. /// /// /// Like all other aspects of the WinINet API, this function cannot be safely called from within DllMain or the constructors and /// destructors of global objects. /// /// /// Note WinINet does not support server implementations. In addition, it should not be used from a service. For server /// implementations or services use Microsoft Windows HTTP Services (WinHTTP). /// /// // https://docs.microsoft.com/en-us/windows/win32/api/wininet/nf-wininet-httpsendrequesta BOOLAPI HttpSendRequestA( HINTERNET // hRequest, LPCSTR lpszHeaders, DWORD dwHeadersLength, LPVOID lpOptional, DWORD dwOptionalLength ); [DllImport(Lib.WinInet, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("wininet.h", MSDNShortId = "f53d9ff7-43b1-452f-a6cb-754d0229ab9a")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool HttpSendRequest(HINTERNET hRequest, [MarshalAs(UnmanagedType.LPTStr), Optional] string lpszHeaders, [Optional] uint dwHeadersLength, [Optional] IntPtr lpOptional, [Optional] uint dwOptionalLength); /// /// Sends the specified request to the HTTP server. /// Callers that need to send extra data beyond what is normally passed to HttpSendRequestEx can do so by /// calling HttpSendRequest instead. /// /// A handle returned by a call to the HttpOpenRequest function. /// Optional. A pointer to an INTERNET_BUFFERS structure. /// Reserved. Must be NULL. /// Reserved. Must be zero. /// Application-defined context value, if a status callback function has been registered. /// /// If the function succeeds, the function returns TRUE. /// If the function fails, it returns FALSE. To get extended error information, call GetLastError. /// /// /// /// HttpSendRequestEx performs both the send and the receive for the response. This does not allow the application to send /// any extra data beyond the single buffer that was passed to HttpSendRequestEx. Callers that need to send extra data beyond /// what is normally passed to HttpSendRequestEx can do so by calling HttpSendRequest instead. After the call to /// HttpSendRequestEx, send the remaining data by calling InternetWriteFile. Finally, follow up with a call to HttpEndRequest. /// /// The HttpSendRequestExA function represents data to send as ISO-8859-1 characters not ANSI characters. /// The HttpSendRequestExW function represents data to send as ISO-8859-1 characters converted to UTF-16LE characters. As a /// result, it is never safe to use the HttpSendRequestExW function when the headers to be added can contain non-ASCII /// characters. Instead, an application can use the MultiByteToWideChar and WideCharToMultiByte functions with a Codepage parameter /// set to 28591 to map between ANSI characters and UTF-16LE characters.WinINet does not support server /// implementations. In addition, it should not be used from a service. For server implementations or services use Microsoft Windows /// HTTP Services (WinHTTP). /// // https://docs.microsoft.com/en-us/windows/win32/api/wininet/nf-wininet-httpsendrequestexa BOOLAPI HttpSendRequestExA( HINTERNET // hRequest, LPINTERNET_BUFFERSA lpBuffersIn, LPINTERNET_BUFFERSA lpBuffersOut, DWORD dwFlags, DWORD_PTR dwContext ); [DllImport(Lib.WinInet, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("wininet.h", MSDNShortId = "3362fcd2-e8df-4886-9525-bf60589b2c1f")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool HttpSendRequestEx(HINTERNET hRequest, in INTERNET_BUFFERS lpBuffersIn, [Optional] IntPtr lpBuffersOut, [Optional] uint dwFlags, [Optional] IntPtr dwContext); /// /// Sends the specified request to the HTTP server. /// Callers that need to send extra data beyond what is normally passed to HttpSendRequestEx can do so by /// calling HttpSendRequest instead. /// /// A handle returned by a call to the HttpOpenRequest function. /// Optional. A pointer to an INTERNET_BUFFERS structure. /// Reserved. Must be NULL. /// Reserved. Must be zero. /// Application-defined context value, if a status callback function has been registered. /// /// If the function succeeds, the function returns TRUE. /// If the function fails, it returns FALSE. To get extended error information, call GetLastError. /// /// /// /// HttpSendRequestEx performs both the send and the receive for the response. This does not allow the application to send /// any extra data beyond the single buffer that was passed to HttpSendRequestEx. Callers that need to send extra data beyond /// what is normally passed to HttpSendRequestEx can do so by calling HttpSendRequest instead. After the call to /// HttpSendRequestEx, send the remaining data by calling InternetWriteFile. Finally, follow up with a call to HttpEndRequest. /// /// The HttpSendRequestExA function represents data to send as ISO-8859-1 characters not ANSI characters. /// The HttpSendRequestExW function represents data to send as ISO-8859-1 characters converted to UTF-16LE characters. As a /// result, it is never safe to use the HttpSendRequestExW function when the headers to be added can contain non-ASCII /// characters. Instead, an application can use the MultiByteToWideChar and WideCharToMultiByte functions with a Codepage parameter /// set to 28591 to map between ANSI characters and UTF-16LE characters.WinINet does not support server /// implementations. In addition, it should not be used from a service. For server implementations or services use Microsoft Windows /// HTTP Services (WinHTTP). /// // https://docs.microsoft.com/en-us/windows/win32/api/wininet/nf-wininet-httpsendrequestexa BOOLAPI HttpSendRequestExA( HINTERNET // hRequest, LPINTERNET_BUFFERSA lpBuffersIn, LPINTERNET_BUFFERSA lpBuffersOut, DWORD dwFlags, DWORD_PTR dwContext ); [DllImport(Lib.WinInet, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("wininet.h", MSDNShortId = "3362fcd2-e8df-4886-9525-bf60589b2c1f")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool HttpSendRequestEx(HINTERNET hRequest, [Optional] IntPtr lpBuffersIn, [Optional] IntPtr lpBuffersOut, [Optional] uint dwFlags, [Optional] IntPtr dwContext); /// Attempts to make a connection to the Internet. /// This parameter is reserved and must be 0. /// Returns ERROR_SUCCESS if successful, or a system error code otherwise. /// /// /// This function allows an application to first attempt to connect before issuing any requests. A client program can use this to /// evoke the dial-up dialog box. If the attempt fails, the application should enter offline mode. /// /// /// Like all other aspects of the WinINet API, this function cannot be safely called from within DllMain or the constructors and /// destructors of global objects. /// /// /// Note WinINet does not support server implementations. In addition, it should not be used from a service. For server /// implementations or services use Microsoft Windows HTTP Services (WinHTTP). /// /// // https://docs.microsoft.com/en-us/windows/win32/api/wininet/nf-wininet-internetattemptconnect void InternetAttemptConnect( DWORD // dwReserved ); [DllImport(Lib.WinInet, SetLastError = false, ExactSpelling = true)] [PInvokeData("wininet.h", MSDNShortId = "a6f22704-f7ca-4c4d-91c3-304b592db6ca")] public static extern Win32Error InternetAttemptConnect(uint dwReserved = 0); /// Causes the modem to automatically dial the default Internet connection. /// /// Controls this operation. This parameter can be one of the following values. /// /// /// Value /// Meaning /// /// /// INTERNET_AUTODIAL_FAILIFSECURITYCHECK 0x04 /// /// Causes InternetAutodial to fail if file and printer sharing is disabled for Windows 95 or later. Windows Server 2008 and Windows /// Vista: This flag is obsolete. /// /// /// /// INTERNET_AUTODIAL_FORCE_ONLINE 0x01 /// Forces an online Internet connection. /// /// /// INTERNET_AUTODIAL_FORCE_UNATTENDED 0x02 /// Forces an unattended Internet dial-up. /// /// /// INTERNET_AUTODIAL_OVERRIDE_NET_PRESENT 0x08 /// Causes InternetAutodial to dial the modem connection even when a network connection to the Internet is present. /// /// /// /// Handle to the parent window. /// /// If the function succeeds, it returns TRUE. /// If the function fails, it returns FALSE. Applications can call GetLastError to retrieve the error code. /// /// /// /// InternetAutodial does not support double-dial connections, SmartCard authentication, or connections that require /// registry-based certification. /// /// /// Note Starting on Windows Vista and Windows Server 2008, the WinINet dial-up functions use the RAS functions to establish /// a dial-up connection. WinINet supports the functionality documented in the RasDialDlg function. /// /// /// InternetAutodial does not attempt to dial if there is an existing dial-up connection on the system. Also, if there is an /// existing LAN connection, and InternetAutodial is not configured to force dial (set the /// INTERNET_AUTODIAL_FORCE_ONLINE in the dwFlags parameter), InternetAutodial does not attempt to dial the connection /// and returns TRUE. /// /// /// Like all other aspects of the WinINet API, this function cannot be safely called from within DllMain or the constructors and /// destructors of global objects. /// /// /// Note WinINet does not support server implementations. In addition, it should not be used from a service. For server /// implementations or services use Microsoft Windows HTTP Services (WinHTTP). /// /// // https://docs.microsoft.com/en-us/windows/win32/api/wininet/nf-wininet-internetautodial BOOLAPI InternetAutodial( DWORD dwFlags, // HWND hwndParent ); [DllImport(Lib.WinInet, SetLastError = true, ExactSpelling = true)] [PInvokeData("wininet.h", MSDNShortId = "843875a8-6c83-4259-8e46-a04f786eb230")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool InternetAutodial(INTERNET_AUTODIAL dwFlags, HWND hwndParent); /// Disconnects an automatic dial-up connection. /// This parameter is reserved and must be 0. /// /// If the function succeeds, it returns TRUE. /// If the function fails, it returns FALSE. Applications can call GetLastError to retrieve the error code. /// /// /// /// InternetAutoDialHangup returns TRUE if autodial is not enabled, or if autodial is enabled but does not have an /// entry configured on the computer. /// /// /// Like all other aspects of the WinINet API, this function cannot be safely called from within DllMain or the constructors and /// destructors of global objects. /// /// /// Note WinINet does not support server implementations. In addition, it should not be used from a service. For server /// implementations or services use Microsoft Windows HTTP Services (WinHTTP). /// /// // https://docs.microsoft.com/en-us/windows/win32/api/wininet/nf-wininet-internetautodialhangup BOOLAPI InternetAutodialHangup( // DWORD dwReserved ); [DllImport(Lib.WinInet, SetLastError = true, ExactSpelling = true)] [PInvokeData("wininet.h", MSDNShortId = "8aa8ecb8-cacd-4cd9-a00b-5293b28dd6bf")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool InternetAutodialHangup(uint dwReserved = 0); /// Canonicalizes a URL, which includes converting unsafe characters and spaces into escape sequences. /// A pointer to the string that contains the URL to canonicalize. /// A pointer to the buffer that receives the resulting canonicalized URL. /// /// A pointer to a variable that contains the size, in characters, of the lpszBuffer buffer. If the function succeeds, this /// parameter receives the number of characters actually copied to the lpszBuffer buffer, which does not include the terminating /// null character. If the function fails, this parameter receives the required size of the buffer, in characters, which includes /// the terminating null character. /// /// /// /// Controls canonicalization. If no flags are specified, the function converts all unsafe characters and meta sequences (such as /// .,\ .., and ...) to escape sequences. This parameter can be one of the following values. /// /// /// /// Value /// Meaning /// /// /// ICU_BROWSER_MODE /// /// Does not encode or decode characters after "#" or "?", and does not remove trailing white space after "?". If this value is not /// specified, the entire URL is encoded and trailing white space is removed. /// /// /// /// ICU_DECODE /// Converts all %XX sequences to characters, including escape sequences, before the URL is parsed. /// /// /// ICU_ENCODE_PERCENT /// /// Encodes any percent signs encountered. By default, percent signs are not encoded. This value is available in Microsoft Internet /// Explorer 5 and later. /// /// /// /// ICU_ENCODE_SPACES_ONLY /// Encodes spaces only. /// /// /// ICU_NO_ENCODE /// Does not convert unsafe characters to escape sequences. /// /// /// ICU_NO_META /// Does not remove meta sequences (such as "." and "..") from the URL. /// /// /// /// /// /// Returns TRUE if successful, or FALSE otherwise. To get extended error information, call the GetLastError function. /// Possible errors include the following. /// /// /// /// Return code /// Description /// /// /// ERROR_BAD_PATHNAME /// The URL could not be canonicalized. /// /// /// ERROR_INSUFFICIENT_BUFFER /// /// The canonicalized URL is too large to fit in the buffer provided. The lpdwBufferLength parameter is set to the size, in bytes, /// of the buffer required to hold the canonicalized URL. /// /// /// /// ERROR_INTERNET_INVALID_URL /// The format of the URL is invalid. /// /// /// ERROR_INVALID_PARAMETER /// There is an invalid string, buffer, buffer size, or flags parameter. /// /// /// /// /// /// In Internet Explorer 4.0 and later, InternetCanonicalizeUrl always functions as if the ICU_BROWSER_MODE flag is /// set. Client applications that must canonicalize the entire URL should use either CoInternetParseUrl (with the action /// PARSE_CANONICALIZE and the flag URL_ESCAPE_UNSAFE) or UrlCanonicalize. /// /// /// InternetCanonicalizeUrl always encodes by default, even if the ICU_DECODE flag has been specified. To decode /// without reencoding, use ICU_DECODE | ICU_NO_ENCODE. If the ICU_DECODE flag is used without /// ICU_NO_ENCODE, the URL is decoded before being parsed; unsafe characters are then re-encoded after parsing. This function /// handles arbitrary protocol schemes, but to do so it must make inferences from the unsafe character set. /// /// /// Applications that call InternetCanonicalizeUrl when using Internet Explorer 3.0 (or when setting the /// ICU_ENCODE_PERCENT flag for Internet Explorer 5 and later) should track the usage of this function on a particular URL. /// If unsafe characters in a URL have been converted to escape sequences, using InternetCanonicalizeUrl again on the URL /// (with no flags) causes the escape sequences to be converted to another escape sequence. For example, a blank space in a URL /// would be converted to the escape sequence %20. Calling InternetCanonicalizeUrl again on the URL would cause the escape /// sequence %20 to be converted to the escape sequence %2520, because the % sign is an unsafe character that is reserved for escape /// sequences and is replaced by the function with the escape sequence %25. /// /// /// Like all other aspects of the WinINet API, this function cannot be safely called from within DllMain or the constructors and /// destructors of global objects. /// /// /// Note WinINet does not support server implementations. In addition, it should not be used from a service. For server /// implementations or services use Microsoft Windows HTTP Services (WinHTTP). /// /// // https://docs.microsoft.com/en-us/windows/win32/api/wininet/nf-wininet-internetcanonicalizeurla BOOLAPI InternetCanonicalizeUrlA( // LPCSTR lpszUrl, LPSTR lpszBuffer, LPDWORD lpdwBufferLength, DWORD dwFlags ); [DllImport(Lib.WinInet, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("wininet.h", MSDNShortId = "3bfde980-e478-4960-b41f-e1c8105ef419")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool InternetCanonicalizeUrl(string lpszUrl, StringBuilder lpszBuffer, ref uint lpdwBufferLength, ICU dwFlags); /// /// /// [ InternetCheckConnection is available for use in the operating systems specified in the Requirements section. It may be /// altered or unavailable in subsequent versions. Instead, use NetworkInformation.GetInternetConnectionProfile or the NLM /// Interfaces. ] /// /// Allows an application to check if a connection to the Internet can be established. /// /// /// Pointer to a null-terminated string that specifies the URL to use to check the connection. This value can be NULL. /// /// /// /// Options. FLAG_ICC_FORCE_CONNECTION is the only flag that is currently available. If this flag is set, it forces a connection. A /// sockets connection is attempted in the following order: /// /// /// /// If lpszUrl is non- NULL, the host value is extracted from it and used to ping that specific host. /// /// /// /// If lpszUrl is NULL and there is an entry in the internal server database for the nearest server, the host value is /// extracted from the entry and used to ping that server. /// /// /// /// /// This parameter is reserved and must be 0. /// /// Returns TRUE if a connection is made successfully, or FALSE otherwise. Use GetLastError to retrieve the error /// code. ERROR_NOT_CONNECTED is returned by GetLastError if a connection cannot be made or if the sockets database is /// unconditionally offline. /// /// /// /// InternetCheckConnection is deprecated. InternetCheckConnection does not work in environments that use a web proxy /// server to access the Internet. Depending on the environment, use NetworkInformation.GetInternetConnectionProfile or the NLM /// Interfaces to check for Internet access instead. /// /// /// Note WinINet does not support server implementations. In addition, it should not be used from a service. For server /// implementations or services use Microsoft Windows HTTP Services (WinHTTP). /// /// // https://docs.microsoft.com/en-us/windows/win32/api/wininet/nf-wininet-internetcheckconnectiona BOOLAPI InternetCheckConnectionA( // LPCSTR lpszUrl, DWORD dwFlags, DWORD dwReserved ); [DllImport(Lib.WinInet, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("wininet.h", MSDNShortId = "4666e4ee-057e-452d-ac2c-d03321a0073f")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool InternetCheckConnection([Optional] string lpszUrl, [Optional] FLAG_ICC dwFlags, uint dwReserved = 0); /// Clears all decisions that were made about cookies on a site by site basis. /// Returns TRUE if all decisions were cleared and FALSE otherwise. /// /// Note WinINet does not support server implementations. In addition, it should not be used from a service. For server /// implementations or services use Microsoft Windows HTTP Services (WinHTTP). /// // https://docs.microsoft.com/en-us/windows/win32/api/wininet/nf-wininet-internetclearallpersitecookiedecisions BOOLAPI // InternetClearAllPerSiteCookieDecisions( ); [DllImport(Lib.WinInet, SetLastError = true, ExactSpelling = true)] [PInvokeData("wininet.h", MSDNShortId = "980df63e-70b8-44d3-b98a-b7c8a3e395c6")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool InternetClearAllPerSiteCookieDecisions(); /// Closes a single Internet handle. /// Handle to be closed. /// /// Returns TRUE if the handle is successfully closed, or FALSE otherwise. To get extended error information, call GetLastError. /// /// /// The function terminates any pending operations on the handle and discards any outstanding data. /// /// It is safe to call InternetCloseHandle as long as no API calls are being made or will be made using the handle. Once an /// API has returned ERROR_IO_PENDING, it is safe to call InternetCloseHandle to cancel that I/O, as long as no /// subsequent API calls will be issued with the handle. /// /// /// It is safe to call InternetCloseHandle in a callback for the handle being closed. If there is a status callback /// registered for the handle being closed, and the handle was created with a non-NULL context value, an /// INTERNET_STATUS_HANDLE_CLOSING callback will be made. This indication will be the last callback made from a handle and /// indicates that the handle is being destroyed. /// /// /// If asynchronous requests are pending for the handle or any of its child handles, the handle cannot be closed immediately, but it /// will be invalidated. Any new requests attempted using the handle will return with an ERROR_INVALID_HANDLE notification. The /// asynchronous requests will complete with INTERNET_STATUS_REQUEST_COMPLETE. Applications must be prepared to receive any /// INTERNET_STATUS_REQUEST_COMPLETE indications on the handle before the final INTERNET_STATUS_HANDLE_CLOSING /// indication is made, which indicates that the handle is completely closed. /// /// /// An application can call GetLastError to determine if requests are pending. If GetLastError returns /// ERROR_IO_PENDING, there were outstanding requests when the handle was closed. /// /// /// Like all other aspects of the WinINet API, this function cannot be safely called from within DllMain or the constructors and /// destructors of global objects. /// /// /// Note WinINet does not support server implementations. In addition, it should not be used from a service. For server /// implementations or services use Microsoft Windows HTTP Services (WinHTTP). /// /// // https://docs.microsoft.com/en-us/windows/win32/api/wininet/nf-wininet-internetclosehandle BOOLAPI InternetCloseHandle( HINTERNET // hInternet ); [DllImport(Lib.WinInet, SetLastError = true, ExactSpelling = true)] [PInvokeData("wininet.h", MSDNShortId = "52b57e3c-3cfe-40bc-b87b-90cf39c5c38d")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool InternetCloseHandle(HINTERNET hInternet); /// /// Checks for changes between secure and nonsecure URLs. Always inform the user when a change occurs in security between two URLs. /// Typically, an application should allow the user to acknowledge the change through interaction with a dialog box. /// /// Handle to the parent window for any required dialog box. /// /// Pointer to a null-terminated string that specifies the URL that was viewed before the current request was made. /// /// Pointer to a null-terminated string that specifies the new URL that the user has requested to view. /// Not implemented. /// /// Returns one of the following values. /// /// /// Return code /// Description /// /// /// ERROR_SUCCESS /// The user confirmed that it was okay to continue, or there was no user input required. /// /// /// ERROR_CANCELLED /// The user canceled the request. /// /// /// ERROR_NOT_ENOUGH_MEMORY /// There is not enough memory to carry out the request. /// /// /// /// /// /// Always inform the user when a change in security level occurs, or you risk subjecting the user to involuntary information disclosure. /// /// /// Like all other aspects of the WinINet API, this function cannot be safely called from within DllMain or the constructors and /// destructors of global objects. /// /// /// Note WinINet does not support server implementations. In addition, it should not be used from a service. For server /// implementations or services use Microsoft Windows HTTP Services (WinHTTP). /// /// // https://docs.microsoft.com/en-us/windows/win32/api/wininet/nf-wininet-internetconfirmzonecrossing void // InternetConfirmZoneCrossing( HWND hWnd, LPSTR szUrlPrev, LPSTR szUrlNew, BOOL bPost ); [DllImport(Lib.WinInet, SetLastError = false, CharSet = CharSet.Auto)] [PInvokeData("wininet.h", MSDNShortId = "e14f58df-5457-4a17-919c-6a25691c2ee1")] public static extern Win32Error InternetConfirmZoneCrossing(HWND hWnd, string szUrlPrev, string szUrlNew, [MarshalAs(UnmanagedType.Bool)] bool bPost = false); /// Opens an File Transfer Protocol (FTP) or HTTP session for a given site. /// Handle returned by a previous call to InternetOpen. /// /// Pointer to a null-terminated string that specifies the host name of an Internet server. Alternately, the string can /// contain the IP number of the site, in ASCII dotted-decimal format (for example, 11.0.1.45). /// /// /// /// Transmission Control Protocol/Internet Protocol (TCP/IP) port on the server. These flags set only the port that is used. The /// service is set by the value of dwService. This parameter can be one of the following values. /// /// /// /// Value /// Meaning /// /// /// INTERNET_DEFAULT_FTP_PORT /// Uses the default port for FTP servers (port 21). /// /// /// INTERNET_DEFAULT_GOPHER_PORT /// Uses the default port for Gopher servers (port 70). /// /// /// INTERNET_DEFAULT_HTTP_PORT /// Uses the default port for HTTP servers (port 80). /// /// /// INTERNET_DEFAULT_HTTPS_PORT /// Uses the default port for Secure Hypertext Transfer Protocol (HTTPS) servers (port 443). /// /// /// INTERNET_DEFAULT_SOCKS_PORT /// Uses the default port for SOCKS firewall servers (port 1080). /// /// /// INTERNET_INVALID_PORT_NUMBER /// Uses the default port for the service specified by dwService. /// /// /// /// /// Pointer to a null-terminated string that specifies the name of the user to log on. If this parameter is NULL, the /// function uses an appropriate default. For the FTP protocol, the default is "anonymous". /// /// /// Pointer to a null-terminated string that contains the password to use to log on. If both lpszPassword and lpszUsername /// are NULL, the function uses the default "anonymous" password. In the case of FTP, the default password is the user's /// email name. If lpszPassword is NULL, but lpszUsername is not NULL, the function uses a blank password. /// /// /// Type of service to access. This parameter can be one of the following values. /// /// /// Value /// Meaning /// /// /// INTERNET_SERVICE_FTP /// FTP service. /// /// /// INTERNET_SERVICE_GOPHER /// Gopher service. /// /// /// INTERNET_SERVICE_HTTP /// HTTP service. /// /// /// /// /// Options specific to the service used. If dwService is INTERNET_SERVICE_FTP, INTERNET_FLAG_PASSIVE causes the application to use /// passive FTP semantics. /// /// /// Pointer to a variable that contains an application-defined value that is used to identify the application context for the /// returned handle in callbacks. /// /// /// Returns a valid handle to the session if the connection is successful, or NULL otherwise. To retrieve extended error /// information, call GetLastError. An application can also use InternetGetLastResponseInfo to determine why access to the service /// was denied. /// /// /// The following table describes the behavior for the four possible settings of lpszUsername and lpszPassword. /// /// /// lpszUsername /// lpszPassword /// User name sent to FTP server /// Password sent to FTP server /// /// /// NULL /// NULL /// "anonymous" /// User's email name /// /// /// Non-NULL string /// NULL /// lpszUsername /// "" /// /// /// NULL /// Non-NULL string /// ERROR /// ERROR /// /// /// Non-NULL string /// Non-NULL string /// lpszUsername /// lpszPassword /// /// /// /// For FTP sites, InternetConnect actually establishes a connection with the server; for others, the actual connection is /// not established until the application requests a specific transaction. /// /// /// For maximum efficiency, applications using the HTTP protocols should try to minimize calls to InternetConnect and avoid /// calling this function for every transaction requested by the user. One way to accomplish this is to keep a small cache of /// handles returned from InternetConnect; when the user makes a request to a previously accessed server, that session handle /// is still available. /// /// /// After the calling application has finished using the HINTERNET handle returned by InternetConnect, it must be closed /// using the InternetCloseHandle function. /// /// /// Note When a request is sent asynchronous mode (the dwFlags parameter of InternetOpen specifies /// INTERNET_FLAG_ASYNC), and the dwContext parameter is zero ( INTERNET_NO_CALLBACK), the callback function set with /// InternetSetStatusCallback on the connection handle will not be called, however, the call will still be performed in asynchronous mode. /// /// Examples of InternetConnect usage can be found in the following topics. /// /// /// Handling Authentication /// /// /// Asynchronous Example Application /// /// /// /// Like all other aspects of the WinINet API, this function cannot be safely called from within DllMain or the constructors and /// destructors of global objects. /// /// /// Note WinINet does not support server implementations. In addition, it should not be used from a service. For server /// implementations or services use Microsoft Windows HTTP Services (WinHTTP). /// /// // https://docs.microsoft.com/en-us/windows/win32/api/wininet/nf-wininet-internetconnecta void InternetConnectA( HINTERNET // hInternet, LPCSTR lpszServerName, INTERNET_PORT nServerPort, LPCSTR lpszUserName, LPCSTR lpszPassword, DWORD dwService, DWORD // dwFlags, DWORD_PTR dwContext ); [DllImport(Lib.WinInet, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("wininet.h", MSDNShortId = "42b5d733-dccd-4c9d-8820-e358e033077c")] public static extern SafeHINTERNET InternetConnect(HINTERNET hInternet, string lpszServerName, [Optional] INTERNET_PORT nServerPort, [Optional] string lpszUserName, [Optional] string lpszPassword, InternetService dwService, [Optional] InternetApiFlags dwFlags, [Optional] IntPtr dwContext); /// Cracks a URL into its component parts. /// Pointer to a string that contains the canonical URL to be cracked. /// Size of the lpszUrl string, in TCHARs, or zero if lpszUrl is an ASCIIZ string. /// /// Controls the operation. This parameter can be one of the following values. /// /// /// Value /// Meaning /// /// /// ICU_DECODE /// /// Converts encoded characters back to their normal form. This can be used only if the user provides buffers in the URL_COMPONENTS /// structure to copy the components into. /// /// /// /// ICU_ESCAPE /// /// Converts all escape sequences (%xx) to their corresponding characters. This can be used only if the user provides buffers in the /// URL_COMPONENTS structure to copy the components into. /// /// /// /// /// Pointer to a URL_COMPONENTS structure that receives the URL components. /// /// Returns TRUE if the function succeeds, or FALSE otherwise. To get extended error information, call GetLastError. /// /// /// /// The required components are indicated by members of the URL_COMPONENTS structure. Each component has a pointer to the value and /// has a member that stores the length of the stored value. If both the value and the length for a component are equal to zero, /// that component is not returned. Windows Vista and later.: If the pointer to the value of the component is NULL and /// the value of its corresponding length member is nonzero, the address of the first character of the corresponding component in /// the lpszUrl string is stored in the pointer, and the length of the component is stored in the length member. /// /// /// If the pointer contains the address of the user-supplied buffer, the length member must contain the size of the buffer. /// InternetCrackUrl copies the component into the buffer, and the length member is set to the length of the copied /// component, minus 1 for the trailing string terminator. /// /// /// For InternetCrackUrl to work properly, the size of the URL_COMPONENTS structure, in bytes, must be stored in the /// dwStructSize member. /// /// /// Note Do not use InternetCrackUrl on "file://" URLs that contain spaces, because the value returned in the /// dwUrlPathLength member of the URL_COMPONENTS structure pointed to by lpUrlComponents is too large. This is only the case, /// however, with "file://" URLs that contain space characters. /// /// /// Like all other aspects of the WinINet API, this function cannot be safely called from within DllMain or the constructors and /// destructors of global objects. /// /// /// Note WinINet does not support server implementations. In addition, it should not be used from a service. For server /// implementations or services use Microsoft Windows HTTP Services (WinHTTP). /// /// // https://docs.microsoft.com/en-us/windows/win32/api/wininet/nf-wininet-internetcrackurla BOOLAPI InternetCrackUrlA( LPCSTR // lpszUrl, DWORD dwUrlLength, DWORD dwFlags, LPURL_COMPONENTSA lpUrlComponents ); [DllImport(Lib.WinInet, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("wininet.h", MSDNShortId = "30677071-3eb2-4d9c-a0a3-ff11a077f98a")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool InternetCrackUrl(string lpszUrl, uint dwUrlLength, ICU dwFlags, ref URL_COMPONENTS lpUrlComponents); /// Creates a URL from its component parts. /// Pointer to a URL_COMPONENTS structure that contains the components from which to create the URL. /// /// Controls the operation of this function. This parameter can be one or more of the following values. /// /// /// Value /// Meaning /// /// /// ICU_ESCAPE /// /// Converts all unsafe characters to their corresponding escape sequences in the path string pointed to by the lpszUrlPath member /// and in lpszExtraInfo the extra-information string pointed to by the member of the URL_COMPONENTS structure pointed to by the /// lpUrlComponents parameter. The Unicode version of InternetCreateUrl will first try to convert using the system code page. If /// that fails it falls back to UTF-8. /// /// /// /// ICU_USERNAME /// Obsolete — ignored. /// /// /// /// Pointer to a buffer that receives the URL. /// /// Pointer to a variable that specifies the size of the URLlpszUrl buffer, in TCHARs. When the function returns, this /// parameter receives the size of the URL string, excluding the NULL terminator. If GetLastError returns ERROR_INSUFFICIENT_BUFFER, /// this parameter receives the number of bytes required to hold the created URL. /// /// /// Returns TRUE if the function succeeds, or FALSE otherwise. To get extended error information, call GetLastError. /// /// /// /// When specifying scheme in the URL_COMPONENTS structure passed to lpUrlComponents, if lpszScheme is not NULL it will be used for /// the scheme. If lpszScheme is NULL, the scheme can be specified using the INTERNET_SCHEME enumeration by setting nScheme /// to the required INTERNET_SCHEME or INTERNET_SCHEME_DEFAULT. /// /// /// Note WinINet does not support server implementations. In addition, it should not be used from a service. For server /// implementations or services use Microsoft Windows HTTP Services (WinHTTP). /// /// // https://docs.microsoft.com/en-us/windows/win32/api/wininet/nf-wininet-internetcreateurla BOOLAPI InternetCreateUrlA( // LPURL_COMPONENTSA lpUrlComponents, DWORD dwFlags, LPSTR lpszUrl, LPDWORD lpdwUrlLength ); [DllImport(Lib.WinInet, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("wininet.h", MSDNShortId = "b01bb684-0b2f-4c17-ab32-9f83fdd89e69")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool InternetCreateUrl(ref URL_COMPONENTS lpUrlComponents, ICU dwFlags, StringBuilder lpszUrl, ref uint lpdwUrlLength); /// Creates a URL from its component parts. /// Pointer to a URL_COMPONENTS structure that contains the components from which to create the URL. /// /// Controls the operation of this function. This parameter can be one or more of the following values. /// /// /// Value /// Meaning /// /// /// ICU_ESCAPE /// /// Converts all unsafe characters to their corresponding escape sequences in the path string pointed to by the lpszUrlPath member /// and in lpszExtraInfo the extra-information string pointed to by the member of the URL_COMPONENTS structure pointed to by the /// lpUrlComponents parameter. The Unicode version of InternetCreateUrl will first try to convert using the system code page. If /// that fails it falls back to UTF-8. /// /// /// /// ICU_USERNAME /// Obsolete — ignored. /// /// /// /// Pointer to a buffer that receives the URL. /// /// Pointer to a variable that specifies the size of the URLlpszUrl buffer, in TCHARs. When the function returns, this /// parameter receives the size of the URL string, excluding the NULL terminator. If GetLastError returns ERROR_INSUFFICIENT_BUFFER, /// this parameter receives the number of bytes required to hold the created URL. /// /// /// Returns TRUE if the function succeeds, or FALSE otherwise. To get extended error information, call GetLastError. /// /// /// /// When specifying scheme in the URL_COMPONENTS structure passed to lpUrlComponents, if lpszScheme is not NULL it will be used for /// the scheme. If lpszScheme is NULL, the scheme can be specified using the INTERNET_SCHEME enumeration by setting nScheme /// to the required INTERNET_SCHEME or INTERNET_SCHEME_DEFAULT. /// /// /// Note WinINet does not support server implementations. In addition, it should not be used from a service. For server /// implementations or services use Microsoft Windows HTTP Services (WinHTTP). /// /// // https://docs.microsoft.com/en-us/windows/win32/api/wininet/nf-wininet-internetcreateurla BOOLAPI InternetCreateUrlA( // LPURL_COMPONENTSA lpUrlComponents, DWORD dwFlags, LPSTR lpszUrl, LPDWORD lpdwUrlLength ); [DllImport(Lib.WinInet, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("wininet.h", MSDNShortId = "b01bb684-0b2f-4c17-ab32-9f83fdd89e69")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool InternetCreateUrl(ref URL_COMPONENTS lpUrlComponents, ICU dwFlags, IntPtr lpszUrl, ref uint lpdwUrlLength); /// Initiates a connection to the Internet using a modem. /// Handle to the parent window. /// /// Pointer to a null-terminated string that specifies the name of the dial-up connection to be used. If this parameter /// contains the empty string (""), the user chooses the connection. If this parameter is NULL, the function connects to the /// autodial connection. /// /// /// Options. This parameter can be one of the following values. /// /// /// Value /// Meaning /// /// /// INTERNET_AUTODIAL_FORCE_ONLINE /// Forces an online connection. /// /// /// INTERNET_AUTODIAL_FORCE_UNATTENDED /// Forces an unattended Internet dial-up. If user intervention is required, the function will fail. /// /// /// INTERNET_DIAL_FORCE_PROMPT /// Ignores the "dial automatically" setting and forces the dialing user interface to be displayed. /// /// /// INTERNET_DIAL_UNATTENDED /// /// Connects to the Internet through a modem, without displaying a user interface, if possible. Otherwise, the function will wait /// for user input. /// /// /// /// INTERNET_DIAL_SHOW_OFFLINE /// Shows the Work Offline button instead of the Cancel button in the dialing user interface. /// /// /// /// /// Pointer to a variable that specifies the connection number. This number is a unique indentifier for the connection that can be /// used in other functions, such as InternetHangUp. /// /// This parameter is reserved and must be NULL. /// /// Returns ERROR_SUCCESS if successful, or an error value otherwise. The error code can be one of the following values. /// /// /// Return code /// Description /// /// /// ERROR_INVALID_PARAMETER /// One or more of the parameters are incorrect. /// /// /// ERROR_NO_CONNECTION /// There is a problem with the dial-up connection. /// /// /// ERROR_USER_DISCONNECTION /// The user clicked either the Work Offline or Cancel button on the Internet connection dialog box. /// /// /// /// /// /// InternetDial does not support double-dial connections, SmartCard authentication, or connections that require /// registry-based certification. /// /// /// Note Starting on Windows Vista and Windows Server 2008, the WinINet dial-up functions use the RAS functions to establish /// a dial-up connection. WinINet supports the functionality documented in the RasDialDlg function. /// /// /// Like all other aspects of the WinINet API, this function cannot be safely called from within DllMain or the constructors and /// destructors of global objects. /// /// /// Note WinINet does not support server implementations. In addition, it should not be used from a service. For server /// implementations or services use Microsoft Windows HTTP Services (WinHTTP). /// /// // https://docs.microsoft.com/en-us/windows/win32/api/wininet/nf-wininet-internetdial void InternetDial( HWND hwndParent, LPSTR // lpszConnectoid, DWORD dwFlags, LPDWORD lpdwConnection, DWORD dwReserved ); [DllImport(Lib.WinInet, SetLastError = false, CharSet = CharSet.Auto)] [PInvokeData("wininet.h", MSDNShortId = "b8ce748b-9879-4f68-aea1-32e2bfaee8ab")] public static extern Win32Error InternetDial(HWND hwndParent, [Optional] string lpszConnectoid, INTERNET_DIAL dwFlags, out uint lpdwConnection, uint dwReserved = 0); /// Retrieves the domains and cookie settings of websites for which site-specific cookie regulations are set. /// An LPSTR that receives a string specifying a website domain. /// /// A pointer to an unsigned long that specifies the size of the pcSiteNameSize parameter provided to the /// InternetEnumPerSiteCookieDecision function when it is called. When InternetEnumPerSiteCookieDecision returns, /// pcSiteNameSize receives the actual length of the domain string returned in pszSiteName. /// /// /// Pointer to an unsigned long that receives the InternetCookieState enumeration value corresponding to pszSiteName. /// /// An unsigned long that specifies the index of the website and corresponding cookie setting to retrieve. /// TRUE if the function retrieved the cookie setting for the given domain; otherwise, false. FALSE. /// /// /// InternetEnumPerSiteCookieDecision should be initially called with dwIndex equal to 0. Incrementing the dwIndex parameter /// steps through the list of websites and cookie settings. The end of the list is reached when /// InternetEnumPerSiteCookieDecision returns FALSE and produces the wininet error, ERROR_NO_MORE_ITEMS. /// /// /// Like all other aspects of the WinINet API, this function cannot be safely called from within DllMain or the constructors and /// destructors of global objects. /// /// /// Note WinINet does not support server implementations. In addition, it should not be used from a service. For server /// implementations or services use Microsoft Windows HTTP Services (WinHTTP). /// /// // https://docs.microsoft.com/en-us/windows/win32/api/wininet/nf-wininet-internetenumpersitecookiedecisiona BOOLAPI // InternetEnumPerSiteCookieDecisionA( LPSTR pszSiteName, unsigned long *pcSiteNameSize, unsigned long *pdwDecision, unsigned long // dwIndex ); [DllImport(Lib.WinInet, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("wininet.h", MSDNShortId = "de1db7e6-21f4-4bbb-b4fc-277bbd01f32c")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool InternetEnumPerSiteCookieDecision(StringBuilder pszSiteName, ref uint pcSiteNameSize, out InternetCookieState pdwDecision, uint dwIndex); /// /// Displays a dialog box for the error that is passed to InternetErrorDlg, if an appropriate dialog box exists. If the /// FLAGS_ERROR_UI_FILTER_FOR_ERRORS flag is used, the function also checks the headers for any hidden errors and displays a /// dialog box if needed. /// /// /// Handle to the parent window for any needed dialog box. If no dialog box is needed and FLAGS_ERROR_UI_FLAGS_NO_UI is /// passed to dwFlags, then this parameter can be NULL. /// /// Handle to the Internet connection used in the call to HttpSendRequest. /// /// Error value for which to display a dialog box. This parameter can be one of the following values. /// /// /// Value /// Meaning /// /// /// ERROR_HTTP_REDIRECT_NEEDS_CONFIRMATION /// Allows the user to confirm the redirect. /// /// /// ERROR_INTERNET_BAD_AUTO_PROXY_SCRIPT /// Displays a dialog indicating that the auto proxy script is invalid. /// /// /// ERROR_INTERNET_CHG_POST_IS_NON_SECURE /// Displays a dialog asking the user whether to post the given data on a non-secure channel. /// /// /// ERROR_INTERNET_CLIENT_AUTH_CERT_NEEDED /// /// The server is requesting a client certificate. The return value for this error is always ERROR_SUCCESS, regardless of whether or /// not the user has selected a certificate. If the user has not selected a certificate then anonymous client authentication will be /// attempted on the subsequent request. /// /// /// /// ERROR_INTERNET_HTTP_TO_HTTPS_ON_REDIR /// Notifies the user of the zone crossing to a secure site. /// /// /// ERROR_INTERNET_HTTPS_TO_HTTP_ON_REDIR /// Notifies the user of the zone crossing from a secure site. /// /// /// ERROR_INTERNET_HTTPS_HTTP_SUBMIT_REDIR /// Notifies the user that the data being posted is now being redirected to a non-secure site. /// /// /// ERROR_INTERNET_INCORRECT_PASSWORD /// Displays a dialog box requesting the user's name and password. /// /// /// ERROR_INTERNET_INVALID_CA /// /// Indicates that the SSL certificate Common Name (host name field) is incorrect. Displays an Invalid SSL Common Name dialog box /// and lets the user view the incorrect certificate. /// /// /// /// ERROR_INTERNET_MIXED_SECURITY /// Displays a warning to the user concerning mixed secure and non-secure content. /// /// /// ERROR_INTERNET_POST_IS_NON_SECURE /// Displays a dialog asking the user whether to post the given data on a non-secure channel. /// /// /// ERROR_INTERNET_SEC_CERT_CN_INVALID /// /// Indicates that the SSL certificate Common Name (host name field) is incorrect. Displays an Invalid SSL Common Name dialog box /// and lets the user view the incorrect certificate. Also allows the user to select a certificate in response to a server request. /// /// /// /// ERROR_INTERNET_SEC_CERT_ERRORS /// Displays a warning to the user showing the issues with the server certificate. /// /// /// ERROR_INTERNET_SEC_CERT_DATE_INVALID /// Tells the user that the SSL certificate has expired. /// /// /// ERROR_INTERNET_SEC_CERT_REV_FAILED /// Displays a warning to the user showing that the server certificate’s revocation check failed. /// /// /// ERROR_INTERNET_SEC_CERT_REVOKED /// Displays a dialog indicating that the server certificate is revoked. /// /// /// ERROR_INTERNET_UNABLE_TO_DOWNLOAD_SCRIPT /// Displays a dialog indicating that the auto proxy script could not be downloaded. /// /// /// /// /// Actions. This parameter can be one or more of the following values. /// /// /// Value /// Meaning /// /// /// FLAGS_ERROR_UI_FILTER_FOR_ERRORS /// /// Scans the returned headers for errors. Call InternetErrorDlg with this flag set following a call to HttpSendRequest so as to /// detect hidden errors. Authentication errors, for example, are normally hidden because the call to HttpSendRequest completes /// successfully, but by scanning the status codes, InternetErrorDlg can determine that the proxy or server requires authentication. /// /// /// /// FLAGS_ERROR_UI_FLAGS_CHANGE_OPTIONS /// If the function succeeds, stores the results of the dialog box in the Internet handle. /// /// /// FLAGS_ERROR_UI_FLAGS_GENERATE_DATA /// /// Queries the Internet handle for needed information. The function constructs the appropriate data structure for the error. (For /// example, for Cert CN failures, the function grabs the certificate.) /// /// /// /// FLAGS_ERROR_UI_SERIALIZE_DIALOGS /// /// Serializes authentication dialog boxes for concurrent requests on a password cache entry. The lppvData parameter should contain /// the address of a pointer to an INTERNET_AUTH_NOTIFY_DATA structure, and the client should implement a thread-safe, non-blocking /// callback function. /// /// /// /// FLAGS_ERROR_UI_FLAGS_NO_UI /// /// Allows the caller to pass NULL to the hWnd parameter without error. To be used in circumstances in which no user interface is required. /// /// /// /// /// /// Pointer to the address of a data structure. The structure can be different for each error that needs to be handled. /// /// /// Returns one of the following values, or an error value otherwise. /// /// /// Return code /// Description /// /// /// ERROR_SUCCESS /// The function completed successfully. For more information, see ERROR_INTERNET_CLIENT_AUTH_CERT_NEEDED in the dwError parameter. /// /// /// ERROR_CANCELLED /// The function was canceled by the user. /// /// /// ERROR_INTERNET_FORCE_RETRY /// /// This indicates that the function needs to redo its request. In the case of authentication this indicates that the user clicked /// the OK button. /// /// /// /// ERROR_INVALID_HANDLE /// The handle to the parent window is invalid. /// /// /// /// /// Always inform the user when any of the following events occur: /// /// /// ERROR_INTERNET_HTTP_TO_HTTPS_ON_REDIR /// /// /// ERROR_INTERNET_INVALID_CA /// /// /// ERROR_INTERNET_POST_IS_NON_SECURE /// /// /// ERROR_INTERNET_SEC_CERT_CN_INVALID /// /// /// ERROR_INTERNET_SEC_CERT_DATE_INVALID /// /// /// /// Unless the user has explicitly chosen not to be informed of these events, failure to do so exposes the user involuntarily to a /// significant security risk. /// /// /// Like all other aspects of the WinINet API, this function cannot be safely called from within DllMain or the constructors and /// destructors of global objects. /// /// /// Note WinINet does not support server implementations. In addition, it should not be used from a service. For server /// implementations or services use Microsoft Windows HTTP Services (WinHTTP). /// /// // https://docs.microsoft.com/en-us/windows/win32/api/wininet/nf-wininet-interneterrordlg void InternetErrorDlg( HWND hWnd, // HINTERNET hRequest, DWORD dwError, DWORD dwFlags, LPVOID *lppvData ); [DllImport(Lib.WinInet, SetLastError = false, ExactSpelling = true)] [PInvokeData("wininet.h", MSDNShortId = "09384ba9-e5cc-48fd-a52c-15df223f87dc")] public static extern Win32Error InternetErrorDlg(HWND hWnd, HINTERNET hRequest, Win32Error dwError, FLAGS_ERROR_UI dwFlags, in IntPtr lppvData); /// /// Continues a file search started as a result of a previous call to FtpFindFirstFile. /// /// Windows XP and Windows Server 2003 R2 and earlier: Or continues a file search as a result of a previous call to GopherFindFirstFile. /// /// /// /// Handle returned from either FtpFindFirstFile or InternetOpenUrl (directories only). /// Windows XP and Windows Server 2003 R2 and earlier: Also a handle returned from GopherFindFirstFile. /// /// /// /// Pointer to the buffer that receives information about the file or directory. The format of the information placed in the buffer /// depends on the protocol in use. The FTP protocol returns a WIN32_FIND_DATA structure. /// /// Windows XP and Windows Server 2003 R2 and earlier: The Gopher protocol returns a GOPHER_FIND_DATA structure. /// /// /// Returns TRUE if the function succeeds, or FALSE otherwise. To get extended error information, call GetLastError. /// If the function finds no matching files, GetLastError returns ERROR_NO_MORE_FILES. /// /// /// Note WinINet does not support server implementations. In addition, it should not be used from a service. For server /// implementations or services use Microsoft Windows HTTP Services (WinHTTP). /// // https://docs.microsoft.com/en-us/windows/win32/api/wininet/nf-wininet-internetfindnextfilea BOOLAPI InternetFindNextFileA( // HINTERNET hFind, LPVOID lpvFindData ); [DllImport(Lib.WinInet, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("wininet.h", MSDNShortId = "7c53e399-b8a5-4cc0-9ef6-88d9a525d87f")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool InternetFindNextFile(HINTERNET hFind, IntPtr lpvFindData); /// /// Continues a file search started as a result of a previous call to FtpFindFirstFile. /// /// Windows XP and Windows Server 2003 R2 and earlier: Or continues a file search as a result of a previous call to GopherFindFirstFile. /// /// /// /// Handle returned from either FtpFindFirstFile or InternetOpenUrl (directories only). /// Windows XP and Windows Server 2003 R2 and earlier: Also a handle returned from GopherFindFirstFile. /// /// /// /// Pointer to the buffer that receives information about the file or directory. The format of the information placed in the buffer /// depends on the protocol in use. The FTP protocol returns a WIN32_FIND_DATA structure. /// /// Windows XP and Windows Server 2003 R2 and earlier: The Gopher protocol returns a GOPHER_FIND_DATA structure. /// /// /// Returns TRUE if the function succeeds, or FALSE otherwise. To get extended error information, call GetLastError. /// If the function finds no matching files, GetLastError returns ERROR_NO_MORE_FILES. /// /// /// Note WinINet does not support server implementations. In addition, it should not be used from a service. For server /// implementations or services use Microsoft Windows HTTP Services (WinHTTP). /// // https://docs.microsoft.com/en-us/windows/win32/api/wininet/nf-wininet-internetfindnextfilea BOOLAPI InternetFindNextFileA( // HINTERNET hFind, LPVOID lpvFindData ); [DllImport(Lib.WinInet, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("wininet.h", MSDNShortId = "7c53e399-b8a5-4cc0-9ef6-88d9a525d87f")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool InternetFindNextFile(HINTERNET hFind, out WIN32_FIND_DATA lpvFindData); /// /// Using this API is not recommended, use the INetworkListManager::GetConnectivity method instead. /// Retrieves the connected state of the local system. /// /// /// /// Pointer to a variable that receives the connection description. This parameter may return a valid flag even when the function /// returns FALSE. This parameter can be one or more of the following values. /// /// /// /// Value /// Meaning /// /// /// INTERNET_CONNECTION_CONFIGURED 0x40 /// Local system has a valid connection to the Internet, but it might or might not be currently connected. /// /// /// INTERNET_CONNECTION_LAN 0x02 /// Local system uses a local area network to connect to the Internet. /// /// /// INTERNET_CONNECTION_MODEM 0x01 /// Local system uses a modem to connect to the Internet. /// /// /// INTERNET_CONNECTION_MODEM_BUSY 0x08 /// No longer used. /// /// /// INTERNET_CONNECTION_OFFLINE 0x20 /// Local system is in offline mode. /// /// /// INTERNET_CONNECTION_PROXY 0x04 /// Local system uses a proxy server to connect to the Internet. /// /// /// INTERNET_RAS_INSTALLED 0x10 /// Local system has RAS installed. /// /// /// /// This parameter is reserved and must be 0. /// /// /// Returns TRUE if there is an active modem or a LAN Internet connection, or FALSE if there is no Internet /// connection, or if all possible Internet connections are not currently active. For more information, see the Remarks section. /// /// /// When InternetGetConnectedState returns FALSE, the application can call GetLastError to retrieve the error code. /// /// /// /// /// A return value of TRUE from InternetGetConnectedState indicates that at least one connection to the Internet is /// available. It does not guarantee that a connection to a specific host can be established. Applications should always check for /// errors returned from API calls that connect to a server. InternetCheckConnection can be called to determine if a connection to a /// specific destination can be established. /// /// /// A return value of TRUE indicates that either the modem connection is active, or a LAN connection is active and a proxy is /// properly configured for the LAN. A return value of FALSE indicates that neither the modem nor the LAN is connected. If /// FALSE is returned, the INTERNET_CONNECTION_CONFIGURED flag may be set to indicate that autodial is configured to /// "always dial" but is not currently active. If autodial is not configured, the function returns FALSE. /// /// /// Like all other aspects of the WinINet API, this function cannot be safely called from within DllMain or the constructors and /// destructors of global objects. /// /// /// Note WinINet does not support server implementations. In addition, it should not be used from a service. For server /// implementations or services use Microsoft Windows HTTP Services (WinHTTP). /// /// // https://docs.microsoft.com/en-us/windows/win32/api/wininet/nf-wininet-internetgetconnectedstate BOOLAPI // InternetGetConnectedState( LPDWORD lpdwFlags, DWORD dwReserved ); [DllImport(Lib.WinInet, SetLastError = true, ExactSpelling = true)] [PInvokeData("wininet.h", MSDNShortId = "500765b8-fbe4-4bba-894e-cc7f114d9eaa")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool InternetGetConnectedState(out INTERNET_CONNECTION lpdwFlags, uint dwReserved = 0); /// /// /// Using this API is not recommended, use the INetworkListManager::GetConnectivity method instead. /// Retrieves the connected state of the specified Internet connection. /// /// /// /// /// Pointer to a variable that receives the connection description. This parameter may return a valid flag even when the function /// returns FALSE. This parameter can be a combination of the following values. /// /// /// /// Value /// Meaning /// /// /// INTERNET_CONNECTION_CONFIGURED 0x40 /// Local system has a valid connection to the Internet, but it might or might not be currently connected. /// /// /// INTERNET_CONNECTION_LAN 0x02 /// Local system uses a local area network to connect to the Internet. /// /// /// INTERNET_CONNECTION_MODEM 0x01 /// Local system uses a modem to connect to the Internet. /// /// /// INTERNET_CONNECTION_MODEM_BUSY 0x08 /// No longer used. /// /// /// INTERNET_CONNECTION_OFFLINE 0x20 /// Local system is in offline mode. /// /// /// INTERNET_CONNECTION_PROXY 0x04 /// Local system uses a proxy server to connect to the Internet. /// /// /// /// Pointer to a string value that receives the connection name. /// Size of the lpszConnectionName string, in TCHARs. /// This parameter is reserved and must be NULL. /// /// /// Returns TRUE if there is an Internet connection, or FALSE if there is no Internet connection, or if all possible /// Internet connections are not currently active. For more information, see the Remarks section. /// /// When InternetGetConnectedState returns FALSE, the application can call GetLastError to retrieve the error code. /// /// /// /// A return value of TRUE from InternetGetConnectedState indicates that at least one connection to the Internet is /// available. It does not guarantee that a connection to a specific host can be established. Applications should always check for /// errors returned from API calls that connect to a server. InternetCheckConnection can be called to determine if a connection to a /// specific destination can be established. /// /// /// A return value of TRUE indicates that either the modem connection is active, or a LAN connection is active and a proxy is /// properly configured for the LAN. A return value of FALSE indicates that neither the modem nor the LAN is connected. If /// FALSE is returned, the INTERNET_CONNECTION_CONFIGURED flag may be set to indicate that autodial is configured to /// "always dial" but is not currently active. If autodial is not configured, the function returns FALSE. /// /// /// Like all other aspects of the WinINet API, this function cannot be safely called from within DllMain or the constructors and /// destructors of global objects. /// /// /// Note WinINet does not support server implementations. In addition, it should not be used from a service. For server /// implementations or services use Microsoft Windows HTTP Services (WinHTTP). /// /// // https://docs.microsoft.com/en-us/windows/win32/api/wininet/nf-wininet-internetgetconnectedstateex BOOLAPI // InternetGetConnectedStateEx( LPDWORD lpdwFlags, LPSTR lpszConnectionName, DWORD dwNameLen, DWORD dwReserved ); [DllImport(Lib.WinInet, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("wininet.h", MSDNShortId = "0b27b86d-6e55-4022-84ce-d4116d71f124")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool InternetGetConnectedStateEx(out INTERNET_CONNECTION lpdwFlags, StringBuilder lpszConnectionName, uint dwNameLen, uint dwReserved = 0); /// Retrieves the cookie for the specified URL. /// A pointer to a null-terminated string that specifies the URL for which cookies are to be retrieved. /// Not implemented. /// A pointer to a buffer that receives the cookie data. This parameter can be NULL. /// /// A pointer to a variable that specifies the size of the lpszCookieData parameter buffer, in TCHARs. If the function succeeds, the /// buffer receives the amount of data copied to the lpszCookieData buffer. If lpszCookieData is NULL, this parameter /// receives a value that specifies the size of the buffer necessary to copy all the cookie data, expressed as a byte count. /// /// /// If the function succeeds, the function returns TRUE. /// If the function fails, it returns FALSE. To get extended error data, call GetLastError. /// The following error values apply to InternetGetCookie. /// /// /// Return code /// Description /// /// /// ERROR_NO_MORE_ITEMS /// There is no cookie for the specified URL and all its parents. /// /// /// ERROR_INSUFFICIENT_BUFFER /// /// The value passed in lpdwSize is insufficient to copy all the cookie data. The value returned in lpdwSize is the size of the /// buffer necessary to get all the data. /// /// /// /// ERROR_INVALID_PARAMETER /// One or more of the parameters is invalid. The lpszUrl parameter is NULL. /// /// /// /// /// /// InternetGetCookie does not require a call to InternetOpen. InternetGetCookie checks in the windows\cookies /// directory for persistent cookies that have an expiration date set sometime in the future. InternetGetCookie also searches /// memory for any session cookies, that is, cookies that do not have an expiration date that were created in the same process by /// InternetSetCookie, because these cookies are not written to any files. Rules for creating cookie files are internal to the /// system and can change in the future. /// /// /// Like all other aspects of the WinINet API, this function cannot be safely called from within DllMain or the constructors and /// destructors of global objects. /// /// /// Note WinINet does not support server implementations. In addition, it should not be used from a service. For server /// implementations or services use Microsoft Windows HTTP Services (WinHTTP). /// /// // https://docs.microsoft.com/en-us/windows/win32/api/wininet/nf-wininet-internetgetcookiea BOOLAPI InternetGetCookieA( LPCSTR // lpszUrl, LPCSTR lpszCookieName, LPSTR lpszCookieData, LPDWORD lpdwSize ); [DllImport(Lib.WinInet, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("wininet.h", MSDNShortId = "12c1ebab-3954-4995-9e1f-bf29699af396")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool InternetGetCookie(string lpszUrl, [Optional] string lpszCookieName, StringBuilder lpszCookieData, ref uint lpdwSize); /// /// The InternetGetCookieEx function retrieves data stored in cookies associated with a specified URL. Unlike /// InternetGetCookie, InternetGetCookieEx can be used to restrict data retrieved to a single cookie name or, by policy, /// associated with untrusted sites or third-party cookies. /// /// /// A pointer to a null-terminated string that contains the URL with which the cookie to retrieve is associated. This /// parameter cannot be NULL or InternetGetCookieEx fails and returns an ERROR_INVALID_PARAMETER error. /// /// /// A pointer to a null-terminated string that contains the name of the cookie to retrieve. This name is case-sensitive. /// /// A pointer to a buffer to receive the cookie data. /// /// A pointer to a DWORD variable. /// On entry, the variable must contain the size, in TCHARs, of the buffer pointed to by the pchCookieData parameter. /// /// On exit, if the function is successful, this variable contains the number of TCHARs of cookie data copied into the buffer. If /// NULL was passed as the lpszCookieData parameter, or if the function fails with an error of /// ERROR_INSUFFICIENT_BUFFER, the variable contains the size, in BYTEs, of buffer required to receive the cookie data. /// /// /// This parameter cannot be NULL or InternetGetCookieEx fails and returns an ERROR_INVALID_PARAMETER error. /// /// /// /// A flag that controls how the function retrieves cookie data. This parameter can be one of the following values. /// /// /// Value /// Meaning /// /// /// INTERNET_COOKIE_HTTPONLY /// /// Enables the retrieval of cookies that are marked as "HTTPOnly". Do not use this flag if you expose a scriptable interface, /// because this has security implications. It is imperative that you use this flag only if you can guarantee that you will never /// expose the cookie to third-party code by way of an extensibility mechanism you provide. Version: Requires Internet Explorer 8.0 /// or later. /// /// /// /// INTERNET_COOKIE_THIRD_PARTY /// Retrieves only third-party cookies if policy explicitly allows all cookies for the specified URL to be retrieved. /// /// /// INTERNET_FLAG_RESTRICTED_ZONE /// /// Retrieves only cookies that would be allowed if the specified URL were untrusted; that is, if it belonged to the /// URLZONE_UNTRUSTED zone. /// /// /// /// /// Reserved for future use. Set to NULL. /// /// If the function succeeds, the function returns TRUE. /// If the function fails, it returns FALSE. To get a specific error value, call GetLastError. /// If NULL is passed to lpszCookieData, the call will succeed and the function will not set ERROR_INSUFFICIENT_BUFFER. /// The following error codes may be set by this function. /// /// /// Return code /// Description /// /// /// ERROR_INSUFFICIENT_BUFFER /// /// Returned if cookie data retrieved is larger than the buffer size pointed to by the pcchCookieData parameter or if that parameter /// is NULL. /// /// /// /// ERROR_INVALID_PARAMETER /// Returned if either the pchURL or the pcchCookieData parameter is NULL. /// /// /// ERROR_NO_MORE_ITEMS /// Returned if no cookied data as specified could be retrieved. /// /// /// /// /// Note WinINet does not support server implementations. In addition, it should not be used from a service. For server /// implementations or services use Microsoft Windows HTTP Services (WinHTTP). /// // https://docs.microsoft.com/en-us/windows/win32/api/wininet/nf-wininet-internetgetcookieexa BOOLAPI InternetGetCookieExA( LPCSTR // lpszUrl, LPCSTR lpszCookieName, LPSTR lpszCookieData, LPDWORD lpdwSize, DWORD dwFlags, LPVOID lpReserved ); [DllImport(Lib.WinInet, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("wininet.h", MSDNShortId = "5006f009-e217-4fdc-9e4e-800ff5fcbf03")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool InternetGetCookieEx(string lpszUrl, [Optional] string lpszCookieName, StringBuilder lpszCookieData, ref uint lpdwSize, [Optional] INTERNET_COOKIE dwFlags, IntPtr lpReserved = default); /// Retrieves the last error description or server response on the thread calling this function. /// Pointer to a variable that receives an error message pertaining to the operation that failed. /// Pointer to a buffer that receives the error text. /// /// Pointer to a variable that contains the size of the lpszBuffer buffer, in TCHARs. When the function returns, this /// parameter contains the size of the string written to the buffer, not including the terminating zero. /// /// /// Returns TRUE if error text was successfully written to the buffer, or FALSE otherwise. To get extended error /// information, call GetLastError. If the buffer is too small to hold all the error text, GetLastError returns /// ERROR_INSUFFICIENT_BUFFER, and the lpdwBufferLength parameter contains the minimum buffer size required to return all the /// error text. /// /// /// /// The FTP protocols can return additional text information along with most errors. This extended error information can be /// retrieved by using the InternetGetLastResponseInfo function whenever GetLastError returns ERROR_INTERNET_EXTENDED_ERROR /// (occurring after an unsuccessful function call). /// /// /// The buffer pointed to by lpszBuffer must be large enough to hold both the error string and a zero terminator at the end of the /// string. However, note that the value returned in lpdwBufferLength does not include the terminating zero. /// /// /// InternetGetLastResponseInfo can be called multiple times until another function is called on this thread. When another /// function is called, the internal buffer that is storing the last response information is cleared. /// /// /// Like all other aspects of the WinINet API, this function cannot be safely called from within DllMain or the constructors and /// destructors of global objects. /// /// /// Note WinINet does not support server implementations. In addition, it should not be used from a service. For server /// implementations or services use Microsoft Windows HTTP Services (WinHTTP). /// /// // https://docs.microsoft.com/en-us/windows/win32/api/wininet/nf-wininet-internetgetlastresponseinfoa BOOLAPI // InternetGetLastResponseInfoA( LPDWORD lpdwError, LPSTR lpszBuffer, LPDWORD lpdwBufferLength ); [DllImport(Lib.WinInet, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("wininet.h", MSDNShortId = "0aa274c5-0aa0-4eb9-8aef-3128e735759d")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool InternetGetLastResponseInfo(out Win32Error lpdwError, StringBuilder lpszBuffer, ref uint lpdwBufferLength); /// Retrieves a decision on cookies for a given domain. /// An LPCTSTR that points to a string containing a domain. /// A pointer to an unsigned long that contains one of the InternetCookieState enumeration values. /// Returns TRUE if the decision was retrieved and FALSE otherwise. /// /// A return value of FALSE may indicate that the domain pchHostName does not have any site-specific cookie regulations. /// /// WinINet minimizes the domain specified in the pchHostName parameter and sets the cookie policy on the minimum legal domain. For /// example, if the specified host name is widgets.microsoft.com, the policy is set on the minimized host name microsoft.com. /// /// /// Like all other aspects of the WinINet API, this function cannot be safely called from within DllMain or the constructors and /// destructors of global objects. /// /// /// Note WinINet does not support server implementations. In addition, it should not be used from a service. For server /// implementations or services use Microsoft Windows HTTP Services (WinHTTP). /// /// // https://docs.microsoft.com/en-us/windows/win32/api/wininet/nf-wininet-internetgetpersitecookiedecisiona BOOLAPI // InternetGetPerSiteCookieDecisionA( LPCSTR pchHostName, unsigned long *pResult ); [DllImport(Lib.WinInet, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("wininet.h", MSDNShortId = "04fa4c33-077c-4b16-8170-c3770783c98a")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool InternetGetPerSiteCookieDecision(string pchHostName, out InternetCookieState pResult); /// Prompts the user for permission to initiate connection to a URL. /// Pointer to a null-terminated string that specifies the URL of the website for the connection. /// Handle to the parent window. /// /// This parameter can be zero or the following flag. /// /// /// Value /// Meaning /// /// /// INTERNET_GOONLINE_REFRESH /// This flag is not used. /// /// /// /// /// If the function succeeds, it returns TRUE. /// If the function fails, it returns FALSE. Applications can call GetLastError to retrieve the error code. /// If the functions fails, it can return the following error code: /// /// /// Return code /// Description /// /// /// ERROR_INVALID_PARAMETER /// One or more of the parameters is incorrect. The dwFlags parameter contains a value other than zero or INTERNET_GOONLINE_REFRESH. /// /// /// /// /// Note WinINet does not support server implementations. In addition, it should not be used from a service. For server /// implementations or services use Microsoft Windows HTTP Services (WinHTTP). /// // https://docs.microsoft.com/en-us/windows/win32/api/wininet/nf-wininet-internetgoonline BOOLAPI InternetGoOnline( LPSTR lpszURL, // HWND hwndParent, DWORD dwFlags ); [DllImport(Lib.WinInet, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("wininet.h", MSDNShortId = "ed1c0282-5469-49d5-8a8c-b7671d27ebd2")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool InternetGoOnline(string lpszURL, HWND hwndParent, uint dwFlags = 0); /// Instructs the modem to disconnect from the Internet. /// Connection number of the connection to be disconnected. /// This parameter is reserved and must be 0. /// Returns ERROR_SUCCESS if successful, or an error value otherwise. /// /// Note WinINet does not support server implementations. In addition, it should not be used from a service. For server /// implementations or services use Microsoft Windows HTTP Services (WinHTTP). /// // https://docs.microsoft.com/en-us/windows/win32/api/wininet/nf-wininet-internethangup void InternetHangUp( DWORD_PTR dwConnection, // DWORD dwReserved ); [DllImport(Lib.WinInet, SetLastError = false, ExactSpelling = true)] [PInvokeData("wininet.h", MSDNShortId = "5d74532e-14cd-45c1-b16b-b302bed89c12")] public static extern Win32Error InternetHangUp(in uint dwConnection, uint dwReserved = 0); /// /// /// There are two WinINet functions named InternetInitializeAutoProxyDll. The first, which merely refreshes the internal /// state of proxy configuration information from the registry, has a single parameter as documented directly below. /// /// /// The second function, prototyped as pfnInternetInitializeAutoProxyDll, is part of WinINet's limited autoproxy support, and /// must be called by dynamically linking to "JSProxy.dll". For autoproxy support, use Windows HTTP Services (WinHTTP) version 5.1. /// For more information, see WinHTTP AutoProxy Support. /// /// /// This parameter is reserved and must be 0. /// Returns TRUE if successful, or FALSE otherwise. To get extended error information, call GetLastError. /// /// /// Because the InternetInitializeAutoProxyDll function takes time to complete its operation, it should not be called from a /// UI thread. /// /// /// Like all other aspects of the WinINet API, this function cannot be safely called from within DllMain or the constructors and /// destructors of global objects. /// /// /// Note WinINet does not support server implementations. In addition, it should not be used from a service. For server /// implementations or services use Microsoft Windows HTTP Services (WinHTTP). /// /// // https://docs.microsoft.com/en-us/windows/win32/api/wininet/nf-wininet-internetinitializeautoproxydll BOOLAPI // InternetInitializeAutoProxyDll( DWORD dwReserved ); [DllImport(Lib.WinInet, SetLastError = true, ExactSpelling = true)] [PInvokeData("wininet.h", MSDNShortId = "d55d64cb-ee92-4366-a1bb-f5d421ed81c8")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool InternetInitializeAutoProxyDll(uint dwReserved = 0); /// Places a lock on the file that is being used. /// Handle returned by the FtpOpenFile, GopherOpenFile, HttpOpenRequest, or InternetOpenUrl function. /// Pointer to a handle that receives the lock request handle. /// Returns TRUE if successful, or FALSE otherwise. To get a specific error message, call GetLastError. /// /// /// If the HINTERNET handle passed to hInternet was created using INTERNET_FLAG_NO_CACHE_WRITE or INTERNET_FLAG_DONT_CACHE, the /// function creates a temporary file with the extension .tmp, unless it is an HTTPS resource. If the handle was created using /// INTERNET_FLAG_NO_CACHE_WRITE or INTERNET_FLAG_DONT_CACHE and it is accessing an HTTPS resource, /// InternetLockRequestFile fails. /// /// /// Like all other aspects of the WinINet API, this function cannot be safely called from within DllMain or the constructors and /// destructors of global objects. /// /// /// Note WinINet does not support server implementations. In addition, it should not be used from a service. For server /// implementations or services use Microsoft Windows HTTP Services (WinHTTP). /// /// // https://docs.microsoft.com/en-us/windows/win32/api/wininet/nf-wininet-internetlockrequestfile BOOLAPI InternetLockRequestFile( // HINTERNET hInternet, HANDLE *lphLockRequestInfo ); [DllImport(Lib.WinInet, SetLastError = true, ExactSpelling = true)] [PInvokeData("wininet.h", MSDNShortId = "5924d117-1dcd-43d8-817e-02bda302bdd4")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool InternetLockRequestFile(HINTERNET hInternet, out HANDLE lphLockRequestInfo); /// Initializes an application's use of the WinINet functions. /// /// Pointer to a null-terminated string that specifies the name of the application or entity calling the WinINet functions. /// This name is used as the user agent in the HTTP protocol. /// /// /// Type of access required. This parameter can be one of the following values. /// /// /// Value /// Meaning /// /// /// INTERNET_OPEN_TYPE_DIRECT /// Resolves all host names locally. /// /// /// INTERNET_OPEN_TYPE_PRECONFIG /// Retrieves the proxy or direct configuration from the registry. /// /// /// INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY /// /// Retrieves the proxy or direct configuration from the registry and prevents the use of a startup Microsoft JScript or Internet /// Setup (INS) file. /// /// /// /// INTERNET_OPEN_TYPE_PROXY /// /// Passes requests to the proxy unless a proxy bypass list is supplied and the name to be resolved bypasses the proxy. In this /// case, the function uses INTERNET_OPEN_TYPE_DIRECT. /// /// /// /// /// /// Pointer to a null-terminated string that specifies the name of the proxy server(s) to use when proxy access is specified /// by setting dwAccessType to INTERNET_OPEN_TYPE_PROXY. Do not use an empty string, because InternetOpen will use it /// as the proxy name. The WinINet functions recognize only CERN type proxies (HTTP only) and the TIS FTP gateway (FTP only). If /// Microsoft Internet Explorer is installed, these functions also support SOCKS proxies. FTP requests can be made through a CERN /// type proxy either by changing them to an HTTP request or by using InternetOpenUrl. If dwAccessType is not set to /// INTERNET_OPEN_TYPE_PROXY, this parameter is ignored and should be NULL. For more information about listing proxy /// servers, see the Listing Proxy Servers section of Enabling Internet Functionality. /// /// /// /// Pointer to a null-terminated string that specifies an optional list of host names or IP addresses, or both, that should /// not be routed through the proxy when dwAccessType is set to INTERNET_OPEN_TYPE_PROXY. The list can contain wildcards. Do /// not use an empty string, because InternetOpen will use it as the proxy bypass list. If this parameter specifies the /// "<local>" macro, the function bypasses the proxy for any host name that does not contain a period. /// /// /// By default, WinINet will bypass the proxy for requests that use the host names "localhost", "loopback", "127.0.0.1", or "[::1]". /// This behavior exists because a remote proxy server typically will not resolve these addresses properly. Internet Explorer /// 9: You can remove the local computer from the proxy bypass list using the "<-loopback>" macro. /// /// If dwAccessType is not set to INTERNET_OPEN_TYPE_PROXY, this parameter is ignored and should be NULL. /// /// /// Options. This parameter can be a combination of the following values. /// /// /// Value /// Meaning /// /// /// INTERNET_FLAG_ASYNC /// Makes only asynchronous requests on handles descended from the handle returned from this function. /// /// /// INTERNET_FLAG_FROM_CACHE /// /// Does not make network requests. All entities are returned from the cache. If the requested item is not in the cache, a suitable /// error, such as ERROR_FILE_NOT_FOUND, is returned. /// /// /// /// INTERNET_FLAG_OFFLINE /// /// Identical to INTERNET_FLAG_FROM_CACHE. Does not make network requests. All entities are returned from the cache. If the /// requested item is not in the cache, a suitable error, such as ERROR_FILE_NOT_FOUND, is returned. /// /// /// /// /// /// Returns a valid handle that the application passes to subsequent WinINet functions. If InternetOpen fails, it returns /// NULL. To retrieve a specific error message, call GetLastError. /// /// /// /// InternetOpen is the first WinINet function called by an application. It tells the Internet DLL to initialize internal /// data structures and prepare for future calls from the application. When the application finishes using the Internet functions, /// it should call InternetCloseHandle to free the handle and any associated resources. /// /// /// The application can make any number of calls to InternetOpen, though a single call is normally sufficient. The /// application might need to define separate behaviors for each InternetOpen instance, such as different proxy servers /// configured for each. /// /// /// After the calling application has finished using the HINTERNET handle returned by InternetOpen, it must be closed using /// the InternetCloseHandle function. /// /// /// Like all other aspects of the WinINet API, this function cannot be safely called from within DllMain or the constructors and /// destructors of global objects. /// /// /// Note WinINet does not support server implementations. In addition, it should not be used from a service. For server /// implementations or services use Microsoft Windows HTTP Services (WinHTTP). /// /// // https://docs.microsoft.com/en-us/windows/win32/api/wininet/nf-wininet-internetopena void InternetOpenA( LPCSTR lpszAgent, DWORD // dwAccessType, LPCSTR lpszProxy, LPCSTR lpszProxyBypass, DWORD dwFlags ); [DllImport(Lib.WinInet, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("wininet.h", MSDNShortId = "9ec087c9-d484-4763-a527-2ea5c1a0cf28")] public static extern SafeHINTERNET InternetOpen([Optional] string lpszAgent, [Optional] InternetOpenType dwAccessType, [Optional] string lpszProxy, [Optional] string lpszProxyBypass, [Optional] InternetApiFlags dwFlags); /// Opens a resource specified by a complete FTP or HTTP URL. /// /// The handle to the current Internet session. The handle must have been returned by a previous call to InternetOpen. /// /// /// A pointer to a null-terminated string variable that specifies the URL to begin reading. Only URLs beginning with ftp:, /// http:, or https: are supported. /// /// /// A pointer to a null-terminated string that specifies the headers to be sent to the HTTP server. For more information, see /// the description of the lpszHeaders parameter in the HttpSendRequest function. /// /// /// The size of the additional headers, in TCHARs. If this parameter is -1L and lpszHeaders is not NULL, lpszHeaders /// is assumed to be zero-terminated (ASCIIZ) and the length is calculated. /// /// /// This parameter can be one of the following values. /// /// /// Value /// Meaning /// /// /// INTERNET_FLAG_EXISTING_CONNECT /// /// Attempts to use an existing InternetConnect object if one exists with the same attributes required to make the request. This is /// useful only with FTP operations, since FTP is the only protocol that typically performs multiple operations during the same /// session. The WinINet API caches a single connection handle for each HINTERNET handle generated by InternetOpen. InternetOpenUrl /// uses this flag for HTTP and FTP connections. /// /// /// /// INTERNET_FLAG_HYPERLINK /// /// Forces a reload if there was no Expires time and no LastModified time returned from the server when determining whether to /// reload the item from the network. /// /// /// /// INTERNET_FLAG_IGNORE_CERT_CN_INVALID /// /// Disables checking of SSL/PCT-based certificates that are returned from the server against the host name given in the request. /// WinINet functions use a simple check against certificates by comparing for matching host names and simple wildcarding rules. /// /// /// /// INTERNET_FLAG_IGNORE_CERT_DATE_INVALID /// Disables checking of SSL/PCT-based certificates for proper validity dates. /// /// /// INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTP /// /// Disables detection of this special type of redirect. When this flag is used, WinINet transparently allows redirects from HTTPS /// to HTTP URLs. /// /// /// /// INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTPS /// /// Disables the detection of this special type of redirect. When this flag is used, WinINet transparently allows redirects from /// HTTP to HTTPS URLs. /// /// /// /// INTERNET_FLAG_KEEP_CONNECTION /// /// Uses keep-alive semantics, if available, for the connection. This flag is required for Microsoft Network (MSN), NTLM, and other /// types of authentication. /// /// /// /// INTERNET_FLAG_NEED_FILE /// Causes a temporary file to be created if the file cannot be cached. /// /// /// INTERNET_FLAG_NO_AUTH /// Does not attempt authentication automatically. /// /// /// INTERNET_FLAG_NO_AUTO_REDIRECT /// Does not automatically handle redirection in HttpSendRequest. /// /// /// INTERNET_FLAG_NO_CACHE_WRITE /// Does not add the returned entity to the cache. /// /// /// INTERNET_FLAG_NO_COOKIES /// Does not automatically add cookie headers to requests, and does not automatically add returned cookies to the cookie database. /// /// /// INTERNET_FLAG_NO_UI /// Disables the cookie dialog box. /// /// /// INTERNET_FLAG_PASSIVE /// Uses passive FTP semantics. InternetOpenUrl uses this flag for FTP files and directories. /// /// /// INTERNET_FLAG_PRAGMA_NOCACHE /// Forces the request to be resolved by the origin server, even if a cached copy exists on the proxy. /// /// /// INTERNET_FLAG_RAW_DATA /// /// Returns the data as a WIN32_FIND_DATA structure when retrieving FTP directory information. If this flag is not specified or if /// the call was made through a CERN proxy, InternetOpenUrl returns the HTML version of the directory. Windows XP and Windows Server /// 2003 R2 and earlier: Also returns data as a GOPHER_FIND_DATA structure when retrieving Gopher directory information. /// /// /// /// INTERNET_FLAG_RELOAD /// Forces a download of the requested file, object, or directory listing from the origin server, not from the cache. /// /// /// INTERNET_FLAG_RESYNCHRONIZE /// /// Reloads HTTP resources if the resource has been modified since the last time it was downloaded. All FTP resources are reloaded. /// Windows XP and Windows Server 2003 R2 and earlier: Gopher resources are also reloaded. /// /// /// /// INTERNET_FLAG_SECURE /// /// Uses secure transaction semantics. This translates to using Secure Sockets Layer/Private Communications Technology (SSL/PCT) and /// is only meaningful in HTTP requests. /// /// /// /// /// /// A pointer to a variable that specifies the application-defined value that is passed, along with the returned handle, to any /// callback functions. /// /// /// Returns a valid handle to the URL if the connection is successfully established, or NULL if the connection fails. To /// retrieve a specific error message, call GetLastError. To determine why access to the service was denied, call InternetGetLastResponseInfo. /// /// /// Call InternetCanonicalizeUrl first if the URL being used contains a relative URL and a base URL separated by blank spaces. /// /// This is a general function that an application can use to retrieve data over any of the protocols that WinINet supports. This /// function is especially useful when the application does not need to access the particulars of a protocol, but only requires the /// data corresponding to a URL. The InternetOpenUrl function parses the URL string, establishes a connection to the server, /// and prepares to download the data identified by the URL. The application can then use InternetReadFile (for files) or /// InternetFindNextFile (for directories) to retrieve the URL data. It is not necessary to call InternetConnect before InternetOpenUrl. /// /// /// Windows XP and Windows Server 2003 R2 and earlier:InternetOpenUrl disables Gopher on ports less than 1024, except /// for port 70—the standard Gopher port—and port 105—typically used for Central Services Organization (CSO) name searches. /// /// /// After the calling application has finished using the HINTERNET handle returned by InternetOpenUrl, it must be closed /// using the InternetCloseHandle function. /// /// /// Note When working in asynchronous mode (the dwFlags parameter of InternetOpen specifies INTERNET_FLAG_ASYNC), and /// the dwContext parameter is zero ( INTERNET_NO_CALLBACK), the callback function set with InternetSetStatusCallback on the /// session handle will not be invoked, however, the call will still be performed in asynchronous mode /// /// /// Like all other aspects of the WinINet API, this function cannot be safely called from within DllMain or the constructors and /// destructors of global objects. /// /// /// Note WinINet does not support server implementations. In addition, it should not be used from a service. For server /// implementations or services use Microsoft Windows HTTP Services (WinHTTP). /// /// // https://docs.microsoft.com/en-us/windows/win32/api/wininet/nf-wininet-internetopenurla void InternetOpenUrlA( HINTERNET // hInternet, LPCSTR lpszUrl, LPCSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD_PTR dwContext ); [DllImport(Lib.WinInet, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("wininet.h", MSDNShortId = "73f969c3-3fa7-43f5-88c5-ba78e59a8d1c")] public static extern SafeHINTERNET InternetOpenUrl(HINTERNET hInternet, string lpszUrl, string lpszHeaders, uint dwHeadersLength, INTERNET_FLAG dwFlags, [Optional] IntPtr dwContext); /// Queries the server to determine the amount of data available. /// Handle returned by the InternetOpenUrl, FtpOpenFile, GopherOpenFile, or HttpOpenRequest function. /// Pointer to a variable that receives the number of available bytes. May be NULL. /// This parameter is reserved and must be 0. /// This parameter is reserved and must be 0. /// /// Returns TRUE if the function succeeds, or FALSE otherwise. To get extended error information, call GetLastError. /// If the function finds no matching files, GetLastError returns ERROR_NO_MORE_FILES. /// /// /// /// This function returns the number of bytes of data that are available to be read immediately by a subsequent call to /// InternetReadFile. If there is currently no data available and the end of the file has not been reached, the request waits until /// data becomes available. The amount of data remaining will not be recalculated until all available data indicated by the call to /// InternetQueryDataAvailable is read. /// /// /// For HINTERNET handles created by HttpOpenRequest and sent by HttpSendRequestEx, a call to HttpEndRequest must be made on the /// handle before InternetQueryDataAvailable can be used. /// /// /// Like all other aspects of the WinINet API, this function cannot be safely called from within DllMain or the constructors and /// destructors of global objects. /// /// /// Note WinINet does not support server implementations. In addition, it should not be used from a service. For server /// implementations or services use Microsoft Windows HTTP Services (WinHTTP). /// /// // https://docs.microsoft.com/en-us/windows/win32/api/wininet/nf-wininet-internetquerydataavailable BOOLAPI // InternetQueryDataAvailable( HINTERNET hFile, LPDWORD lpdwNumberOfBytesAvailable, DWORD dwFlags, DWORD_PTR dwContext ); [DllImport(Lib.WinInet, SetLastError = true, ExactSpelling = true)] [PInvokeData("wininet.h", MSDNShortId = "fea8250d-f260-421f-b4dd-14b8685e8dac")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool InternetQueryDataAvailable(HINTERNET hFile, out uint lpdwNumberOfBytesAvailable, uint dwFlags = 0, IntPtr dwContext = default); /// Queries an Internet option on the specified handle. /// Handle on which to query information. /// Internet option to be queried. This can be one of the Option Flags values. /// /// Pointer to a buffer that receives the option setting. Strings returned by InternetQueryOption are globally allocated, so /// the calling application must free them when it is finished using them. /// /// /// Pointer to a variable that contains the size of lpBuffer, in bytes. When InternetQueryOption returns, lpdwBufferLength /// specifies the size of the data placed into lpBuffer. If GetLastError returns ERROR_INSUFFICIENT_BUFFER, this parameter points to /// the number of bytes required to hold the requested information. /// /// Returns TRUE if successful, or FALSE otherwise. To get a specific error message, call GetLastError. /// /// /// GetLastError will return the ERROR_INVALID_PARAMETER if an option flag that is invalid for the specified handle type is /// passed to the dwOption parameter. /// /// For more information, see Setting and Retrieving Internet Options. /// /// Like all other aspects of the WinINet API, this function cannot be safely called from within DllMain or the constructors and /// destructors of global objects. /// /// /// Note WinINet does not support server implementations. In addition, it should not be used from a service. For server /// implementations or services use Microsoft Windows HTTP Services (WinHTTP). /// /// // https://docs.microsoft.com/en-us/windows/win32/api/wininet/nf-wininet-internetqueryoptiona BOOLAPI InternetQueryOptionA( // HINTERNET hInternet, DWORD dwOption, LPVOID lpBuffer, LPDWORD lpdwBufferLength ); [DllImport(Lib.WinInet, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("wininet.h", MSDNShortId = "b0bafd3d-8f54-429e-b423-dae3d61b0030")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool InternetQueryOption(HINTERNET hInternet, InternetOptionFlags dwOption, IntPtr lpBuffer, ref int lpdwBufferLength); /// Queries an Internet option on the specified handle. /// Handle on which to query information. /// Internet option to be queried. This can be one of the Option Flags values. /// /// A instance with sufficient memory needed to hold the response. This should be cast to the type required. /// public static ISafeMemoryHandle InternetQueryOption(HINTERNET hInternet, InternetOptionFlags option) { var sz = 0; InternetQueryOption(hInternet, option, IntPtr.Zero, ref sz); var err = Win32Error.GetLastError(); if (err != Win32Error.ERROR_INSUFFICIENT_BUFFER) err.ThrowIfFailed(); var hMem = new SafeCoTaskMemHandle(sz); var res = InternetQueryOption(hInternet, option, hMem, ref sz); if (!res) Win32Error.ThrowLastError(); return hMem; } /// Queries an Internet option on the specified handle. /// The expected type returned by the option. /// Handle on which to query information. /// Internet option to be queried. This can be one of the Option Flags values. /// The option setting. public static T InternetQueryOption(HINTERNET hInternet, InternetOptionFlags option) { if (!CorrespondingTypeAttribute.CanGet(option, typeof(T))) throw new ArgumentException($"{option} cannot be used to get values of type {typeof(T)}."); using (var hMem = InternetQueryOption(hInternet, option)) return typeof(T) == typeof(string) ? (T)(object)hMem.ToString(-1) : (typeof(T) == typeof(bool) ? (T)(object)Convert.ToBoolean(hMem.ToStructure()) : hMem.ToStructure()); } /// Reads data from a handle opened by the InternetOpenUrl, FtpOpenFile, or HttpOpenRequest function. /// Handle returned from a previous call to InternetOpenUrl, FtpOpenFile, or HttpOpenRequest. /// Pointer to a buffer that receives the data. /// Number of bytes to be read. /// /// Pointer to a variable that receives the number of bytes read. InternetReadFile sets this value to zero before doing any /// work or error checking. /// /// /// Returns TRUE if successful, or FALSE otherwise. To get extended error information, call GetLastError. An /// application can also use InternetGetLastResponseInfo when necessary. /// /// /// /// InternetReadFile operates much like the base ReadFile function, with a few exceptions. Typically, InternetReadFile /// retrieves data from an HINTERNET handle as a sequential stream of bytes. The amount of data to be read for each call to /// InternetReadFile is specified by the dwNumberOfBytesToRead parameter and the data is returned in the lpBuffer parameter. /// A normal read retrieves the specified dwNumberOfBytesToRead for each call to InternetReadFile until the end of the file /// is reached. To ensure all data is retrieved, an application must continue to call the InternetReadFile function until the /// function returns TRUE and the lpdwNumberOfBytesRead parameter equals zero. This is especially important if the requested /// data is written to the cache, because otherwise the cache will not be properly updated and the file downloaded will not be /// committed to the cache. Note that caching happens automatically unless the original request to open the data stream set the /// INTERNET_FLAG_NO_CACHE_WRITE flag. /// /// /// When an application retrieves a handle using InternetOpenUrl, WinINet attempts to make all data look like a file download, in an /// effort to make reading from the Internet easier for the application. For some types of information, such as FTP file directory /// listings, it converts the data to be returned by InternetReadFile to an HTML stream. It does this on a line-by-line /// basis. For example, it can convert an FTP directory listing to a line of HTML and return this HTML to the application. /// /// /// WinINet attempts to write the HTML to the lpBuffer buffer a line at a time. If the application's buffer is too small to fit at /// least one line of generated HTML, the error code ERROR_INSUFFICIENT_BUFFER is returned as an indication to the /// application that it needs a larger buffer. Also, converted lines might not completely fill the buffer, so /// InternetReadFile can return with less data in lpBuffer than requested. Subsequent reads will retrieve all the converted /// HTML. The application must again check that all data is retrieved as described previously. /// /// /// Like all other aspects of the WinINet API, this function cannot be safely called from within DllMain or the constructors and /// destructors of global objects. /// /// /// When running asynchronously, if a call to InternetReadFile does not result in a completed transaction, it will return /// FALSE and a subsequent call to GetLastError will return ERROR_IO_PENDING. When the transaction is completed the /// InternetStatusCallback specified in a previous call to InternetSetStatusCallback will be called with INTERNET_STATUS_REQUEST_COMPLETE. /// /// /// Note WinINet does not support server implementations. In addition, it should not be used from a service. For server /// implementations or services use Microsoft Windows HTTP Services (WinHTTP). /// /// // https://docs.microsoft.com/en-us/windows/win32/api/wininet/nf-wininet-internetreadfile BOOLAPI InternetReadFile( HINTERNET hFile, // LPVOID lpBuffer, DWORD dwNumberOfBytesToRead, LPDWORD lpdwNumberOfBytesRead ); [DllImport(Lib.WinInet, SetLastError = true, ExactSpelling = true)] [PInvokeData("wininet.h", MSDNShortId = "1ec0fe70-4749-4251-9c58-44efdab74688")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool InternetReadFile(HINTERNET hFile, IntPtr lpBuffer, uint dwNumberOfBytesToRead, out uint lpdwNumberOfBytesRead); /// Reads data from a handle opened by the InternetOpenUrl or HttpOpenRequest function. /// Handle returned by the InternetOpenUrl or HttpOpenRequest function. /// Pointer to an INTERNET_BUFFERS structure that receives the data downloaded. /// /// This parameter can be one of the following values. /// /// /// Value /// Meaning /// /// /// IRF_ASYNC /// Identical to WININET_API_FLAG_ASYNC. /// /// /// IRF_SYNC /// Identical to WININET_API_FLAG_SYNC. /// /// /// IRF_USE_CONTEXT /// Identical to WININET_API_FLAG_USE_CONTEXT. /// /// /// IRF_NO_WAIT /// /// Do not wait for data. If there is data available, the function returns either the amount of data requested or the amount of data /// available (whichever is smaller). /// /// /// /// /// A caller supplied context value used for asynchronous operations. /// /// Returns TRUE if successful, or FALSE otherwise. To get extended error information, call GetLastError. An /// application can also use InternetGetLastResponseInfo when necessary. /// /// /// Note WinINet does not support server implementations. In addition, it should not be used from a service. For server /// implementations or services use Microsoft Windows HTTP Services (WinHTTP). /// // https://docs.microsoft.com/en-us/windows/win32/api/wininet/nf-wininet-internetreadfileexa BOOLAPI InternetReadFileExA( HINTERNET // hFile, LPINTERNET_BUFFERSA lpBuffersOut, DWORD dwFlags, DWORD_PTR dwContext ); [DllImport(Lib.WinInet, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("wininet.h", MSDNShortId = "04e7bb7e-d925-41fd-8333-3cb443a04c5b")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool InternetReadFileEx(HINTERNET hFile, ref INTERNET_BUFFERS lpBuffersOut, IRF dwFlags, [Optional] IntPtr dwContext); /// Creates a cookie associated with the specified URL. /// Pointer to a null-terminated string that specifies the URL for which the cookie should be set. /// /// Pointer to a null-terminated string that specifies the name to be associated with the cookie data. If this parameter is /// NULL, no name is associated with the cookie. /// /// Pointer to the actual data to be associated with the URL. /// Returns TRUE if successful, or FALSE otherwise. To get a specific error message, call GetLastError. /// /// /// Cookies created by InternetSetCookie without an expiration date are stored in memory and are available only in the same /// process that created them. Cookies that include an expiration date are stored in the windows\cookies directory. /// /// /// Creating a new cookie might cause a dialog box to appear on the screen asking the user if they want to allow or disallow cookies /// from this site based on the privacy settings for the user. /// /// /// CautionInternetSetCookie will unconditionally create a cookie even if “Block all cookies” is set in Internet /// Explorer. This behavior can be viewed as a breach of privacy even though such cookies are not subsequently sent back to servers /// while the “Block all cookies” setting is active. Applications should use InternetSetCookieEx to correctly honor the user's /// privacy settings. For more cookie internals, see http://blogs.msdn.com/ieinternals/archive/2009/08/20/WinINET-IE-Cookie-Internals-FAQ.aspx. /// /// /// Like all other aspects of the WinINet API, this function cannot be safely called from within DllMain or the constructors and /// destructors of global objects. /// /// /// Note WinINet does not support server implementations. In addition, it should not be used from a service. For server /// implementations or services use Microsoft Windows HTTP Services (WinHTTP). /// /// // https://docs.microsoft.com/en-us/windows/win32/api/wininet/nf-wininet-internetsetcookiea BOOLAPI InternetSetCookieA( LPCSTR // lpszUrl, LPCSTR lpszCookieName, LPCSTR lpszCookieData ); [DllImport(Lib.WinInet, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("wininet.h", MSDNShortId = "1b1ca72e-9c74-4e94-86a9-6fee12c83933")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool InternetSetCookie(string lpszUrl, [Optional] string lpszCookieName, string lpszCookieData); /// /// The InternetSetCookieEx function creates a cookie with a specified name that is associated with a specified URL. This /// function differs from the InternetSetCookie function by being able to create third-party cookies. /// /// /// Pointer to a null-terminated string that contains the URL for which the cookie should be set. /// If this pointer is NULL, InternetSetCookieEx fails with an ERROR_INVALID_PARAMETER error. /// /// /// Pointer to a null-terminated string that contains the name to associate with this cookie. If this pointer is NULL, /// then no name is associated with the cookie. /// /// /// Pointer to a null-terminated string that contains the data to be associated with the new cookie. /// If this pointer is NULL, InternetSetCookieEx fails with an ERROR_INVALID_PARAMETER error. /// /// /// Flags that control how the function retrieves cookie data: /// /// /// Value /// Meaning /// /// /// INTERNET_COOKIE_EVALUATE_P3P /// /// If this flag is set and the dwReserved parameter is not NULL, then the dwReserved parameter is cast to an LPCTSTR that points to /// a Platform-for-Privacy-Protection (P3P) header for the cookie in question. /// /// /// /// INTERNET_COOKIE_HTTPONLY /// /// Enables the retrieval of cookies that are marked as "HTTPOnly". Do not use this flag if you expose a scriptable interface, /// because this has security implications. If you expose a scriptable interface, you can become an attack vector for cross-site /// scripting attacks. It is utterly imperative that you use this flag only if they can guarantee that you will never permit /// third-party code to set a cookie using this flag by way of an extensibility mechanism you provide. Version: Requires Internet /// Explorer 8.0 or later. /// /// /// /// INTERNET_COOKIE_THIRD_PARTY /// Indicates that the cookie being set is a third-party cookie. /// /// /// INTERNET_FLAG_RESTRICTED_ZONE /// Indicates that the cookie being set is associated with an untrusted site. /// /// /// /// /// NULL, or contains a pointer to a Platform-for-Privacy-Protection (P3P) header to be associated with the cookie. /// /// /// Returns a member of the InternetCookieState enumeration if successful, or FALSE if the function fails. On failure, if a /// call to GetLastError returns ERROR_NOT_ENOUGH_MEMORY, insufficient system memory was available. /// /// /// Note WinINet does not support server implementations. In addition, it should not be used from a service. For server /// implementations or services use Microsoft Windows HTTP Services (WinHTTP). /// // https://docs.microsoft.com/en-us/windows/win32/api/wininet/nf-wininet-internetsetcookieexa void InternetSetCookieExA( LPCSTR // lpszUrl, LPCSTR lpszCookieName, LPCSTR lpszCookieData, DWORD dwFlags, DWORD_PTR dwReserved ); [DllImport(Lib.WinInet, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("wininet.h", MSDNShortId = "5044761f-152d-4606-87d2-c56a11db18c4")] public static extern InternetCookieState InternetSetCookieEx(string lpszUrl, [Optional] string lpszCookieName, string lpszCookieData, INTERNET_COOKIE dwFlags, IntPtr dwReserved = default); /// /// Not supported. /// This function is obsolete. Do not use. /// /// TBD /// TBD /// TBD /// This function does not return a value. /// /// Note WinINet does not support server implementations. In addition, it should not be used from a service. For server /// implementations or services use Microsoft Windows HTTP Services (WinHTTP). /// // https://docs.microsoft.com/en-us/windows/win32/api/wininet/nf-wininet-internetsetdialstate BOOLAPI InternetSetDialState( LPCSTR // lpszConnectoid, DWORD dwState, DWORD dwReserved ); [DllImport(Lib.WinInet, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("wininet.h", MSDNShortId = "f523f1ca-3e5a-4da0-850f-8654c82ee41e")] [Obsolete] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool InternetSetDialState(string lpszConnectoid, uint dwState, uint dwReserved); /// /// Sets a file position for InternetReadFile. This is a synchronous call; however, subsequent calls to InternetReadFile might block /// or return pending if the data is not available from the cache and the server does not support random access. /// /// /// Handle returned from a previous call to InternetOpenUrl (on an HTTP or HTTPS URL) or HttpOpenRequest (using the GET or HEAD HTTP /// verb and passed to HttpSendRequest or HttpSendRequestEx). This handle must not have been created with the /// INTERNET_FLAG_DONT_CACHE or INTERNET_FLAG_NO_CACHE_WRITE value set. /// /// /// The low order 32-bits of a signed 64-bit number of bytes to move the file pointer. Internet Explorer 7 and /// earlier:InternetSetFilePointer used to move the pointer only within the bounds of a LONG. When calling this older /// version of the function, lpDistanceToMoveHigh is reserved and should be set to 0. A positive value moves the pointer /// forward in the file; a negative value moves it backward. /// /// /// A pointer to the high order 32-bits of the signed 64-bit distance to move. If you do not need the high order 32-bits, this /// pointer must be set to NULL. When not NULL, this parameter also receives the high order DWORD of the new value of /// the file pointer. A positive value moves the pointer forward in the file; a negative value moves it backward. Internet /// Explorer 7 and earlier:InternetSetFilePointer used to move the pointer only within the bounds of a LONG. When calling /// this older version of the function, lpDistanceToMoveHigh is reserved and should be set to 0. /// /// /// Starting point for the file pointer move. This parameter can be one of the following values. /// /// /// Value /// Meaning /// /// /// FILE_BEGIN /// /// Starting point is zero or the beginning of the file. If FILE_BEGIN is specified, lDistanceToMove is interpreted as an unsigned /// location for the new file pointer. /// /// /// /// FILE_CURRENT /// Current value of the file pointer is the starting point. /// /// /// FILE_END /// Current end-of-file position is the starting point. This method fails if the content length is unknown. /// /// /// /// This parameter is reserved and must be 0. /// /// /// I the function succeeds, it returns the current file position. A return value of INVALID_SET_FILE_POINTER indicates a /// potential failure and needs to be followed by be a call to GetLastError. /// /// /// Since INVALID_SET_FILE_POINTER is a valid value for the low-order DWORD of the new file pointer, the caller must check /// both the return value of the function and the error code returned by GetLastError to determine whether or not an error has /// occurred. If an error has occurred, the return value of InternetSetFilePointer is INVALID_SET_FILE_POINTER and /// GetLastError returns a value other than NO_ERROR. /// /// /// If the function succeeds and lpDistanceToMoveHigh is NULL, the return value is the low-order DWORD of the new file pointer. /// /// /// If the function succeeds and lpDistanceToMoveHigh is not NULL, the return value is the lower-order DWORD of the /// new file pointer and lpDistanceToMoveHigh contains the high order DWORD of the new file pointer. /// /// /// If a new file pointer is a negative value, the function fails, the file pointer is not moved, and the code returned by /// GetLastError is ERROR_NEGATIVE_SEEK. /// /// /// If lpDistanceToMoveHigh is NULL and the new file position does not fit in a 32-bit value the function fails and returns INVALID_SET_FILE_POINTER. /// /// /// /// This function cannot be used once the end of the file has been reached by InternetReadFile. /// /// For HINTERNET handles created by HttpOpenRequest and sent by HttpSendRequestEx, a call to HttpEndRequest must be made on the /// handle before InternetSetFilePointer is used. /// /// InternetSetFilePointer cannot be used reliably if the content length is unknown. /// /// Like all other aspects of the WinINet API, this function cannot be safely called from within DllMain or the constructors and /// destructors of global objects. /// /// /// InternetSetFilePointer has changed over time. In Internet Explorer 7 and earlier, it used to move the pointer only within /// the bounds of a LONG. When calling this older version of the function, lDistanceToMove contains the entire value. A positive /// value moves the pointer forward in the file; a negative value moves it backward. lpDistanceToMoveHigh is reserved and is set to /// 0. In current versions, lpDistanceToMoveHigh is a significant value and where any negative value would be indicated. /// /// /// Note WinINet does not support server implementations. In addition, it should not be used from a service. For server /// implementations or services use Microsoft Windows HTTP Services (WinHTTP). /// /// // https://docs.microsoft.com/en-us/windows/win32/api/wininet/nf-wininet-internetsetfilepointer void InternetSetFilePointer( // HINTERNET hFile, LONG lDistanceToMove, PLONG lpDistanceToMoveHigh, DWORD dwMoveMethod, DWORD_PTR dwContext ); [DllImport(Lib.WinInet, SetLastError = true, ExactSpelling = true)] [PInvokeData("wininet.h", MSDNShortId = "0fdd85cb-f6a9-4a08-b72b-10d2075efb59")] public static extern uint InternetSetFilePointer(HINTERNET hFile, int lDistanceToMove, in int lpDistanceToMoveHigh, SeekOrigin dwMoveMethod, [Optional] IntPtr dwContext); /// Sets an Internet option. /// Handle on which to set information. /// Internet option to be set. This can be one of the Option Flags values. /// Pointer to a buffer that contains the option setting. /// /// Size of the lpBuffer buffer. If lpBuffer contains a string, the size is in TCHARs. If lpBuffer contains anything other /// than a string, the size is in bytes. /// /// Returns TRUE if successful, or FALSE otherwise. To get a specific error message, call GetLastError. /// /// GetLastError will return the error ERROR_INVALID_PARAMETER if an option flag that cannot be set is specified. /// For more information, see Setting and Retrieving Internet Options. /// /// Like all other aspects of the WinINet API, this function cannot be safely called from within DllMain or the constructors and /// destructors of global objects. /// /// /// Note WinINet does not support server implementations. In addition, it should not be used from a service. For server /// implementations or services use Microsoft Windows HTTP Services (WinHTTP). /// /// // https://docs.microsoft.com/en-us/windows/win32/api/wininet/nf-wininet-internetsetoptiona BOOLAPI InternetSetOptionA( HINTERNET // hInternet, DWORD dwOption, LPVOID lpBuffer, DWORD dwBufferLength ); [DllImport(Lib.WinInet, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("wininet.h", MSDNShortId = "578c7130-7426-4a2e-ae0f-ed8a84449b06")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool InternetSetOption(HINTERNET hInternet, InternetOptionFlags dwOption, IntPtr lpBuffer, int dwBufferLength); /// Sets an Internet option /// Handle on which to set information. /// Internet option to be set. This can be one of the Option Flags values. /// Returns TRUE if successful, or FALSE otherwise. To get a specific error message, call GetLastError. public static bool InternetSetOption(HINTERNET hInternet, InternetOptionFlags option) { var attrs = CorrespondingTypeAttribute.GetCorrespondingTypes(option, CorrespondingAction.Set); if (!attrs.Any() || attrs.First() != null) throw new ArgumentException($"{option} cannot be used to set options that do not require a value."); return InternetSetOption(hInternet, option, IntPtr.Zero, 0); } /// Sets an Internet option /// The type expected by the option. /// Handle on which to set information. /// Internet option to be set. This can be one of the Option Flags values. /// The option setting value. /// Returns TRUE if successful, or FALSE otherwise. To get a specific error message, call GetLastError. public static bool InternetSetOption(HINTERNET hInternet, InternetOptionFlags option, T value) { if (!CorrespondingTypeAttribute.CanSet(option, typeof(T))) throw new ArgumentException($"{option} cannot be used to set values of type {typeof(T)}."); using (var hMem = typeof(T) == typeof(string) ? new SafeCoTaskMemHandle(value?.ToString()) : (typeof(T) == typeof(bool) ? SafeCoTaskMemHandle.CreateFromStructure(Convert.ToUInt32(value)) : SafeCoTaskMemHandle.CreateFromStructure(value))) return InternetSetOption(hInternet, option, hMem, typeof(T) == typeof(string) ? value?.ToString().Length + 1 ?? 0 : (int)hMem.Size); } /// /// Not supported. /// /// Implemented only as a stub that calls the InternetSetOption function; InternetSetOptionEx has no functionality of its /// own. Do not use this function at this time. /// /// /// TBD /// TBD /// TBD /// TBD /// TBD /// This function does not return a value. /// /// Note WinINet does not support server implementations. In addition, it should not be used from a service. For server /// implementations or services use Microsoft Windows HTTP Services (WinHTTP). /// // https://docs.microsoft.com/en-us/windows/win32/api/wininet/nf-wininet-internetsetoptionexa BOOLAPI InternetSetOptionExA( // HINTERNET hInternet, DWORD dwOption, LPVOID lpBuffer, DWORD dwBufferLength, DWORD dwFlags ); [DllImport(Lib.WinInet, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("wininet.h", MSDNShortId = "535e4f38-d941-4b69-8c48-ea47f3fbd5e7")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool InternetSetOptionEx(HINTERNET hInternet, uint dwOption, IntPtr lpBuffer, uint dwBufferLength, uint dwFlags); /// Sets a decision on cookies for a given domain. /// An LPCTSTR that points to a string containing a domain. /// A value of type DWORD that contains one of the InternetCookieState enumeration values. /// Returns TRUE if the decision is set and FALSE otherwise. /// /// /// WinINet minimizes the domain specified in the pchHostName parameter and sets the cookie policy on the minimum legal domain. For /// example, if the specified host name is widgets.microsoft.com, the policy is set on the minimized host name microsoft.com. /// /// /// Like all other aspects of the WinINet API, this function cannot be safely called from within DllMain or the constructors and /// destructors of global objects. /// /// /// Note WinINet does not support server implementations. In addition, it should not be used from a service. For server /// implementations or services use Microsoft Windows HTTP Services (WinHTTP). /// /// // https://docs.microsoft.com/en-us/windows/win32/api/wininet/nf-wininet-internetsetpersitecookiedecisiona BOOLAPI // InternetSetPerSiteCookieDecisionA( LPCSTR pchHostName, DWORD dwDecision ); [DllImport(Lib.WinInet, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("wininet.h", MSDNShortId = "c25699b9-f79a-443b-b9a4-461c379fa8e4")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool InternetSetPerSiteCookieDecision(string pchHostName, InternetCookieState dwDecision); /// /// The InternetSetStatusCallback function sets up a callback function that WinINet functions can call as progress is made during an operation. /// /// The handle for which the callback is set. /// /// A pointer to the callback function to call when progress is made, or NULL to remove the existing callback function. For /// more information about the callback function, see InternetStatusCallback. /// /// /// Returns the previously defined status callback function if successful, NULL if there was no previously defined status /// callback function, or INTERNET_INVALID_STATUS_CALLBACK if the callback function is not valid. /// /// /// /// Both synchronous and asynchronous functions use the callback function to indicate the progress of the request, such as resolving /// a name, connecting to a server, and so on. The callback function is required for an asynchronous operation. The asynchronous /// request will call back to the application with INTERNET_STATUS_REQUEST_COMPLETE to indicate the request has been completed. /// /// /// A callback function can be set on any handle, and is inherited by derived handles. A callback function can be changed using /// InternetSetStatusCallback, providing there are no pending requests that need to use the previous callback value. Note, /// however, that changing the callback function on a handle does not change the callbacks on derived handles, such as that returned /// by InternetConnect. You must change the callback function at each level. /// /// /// Many of the WinINet functions perform several operations on the network. Each operation can take time to complete, and each can fail. /// /// /// It is sometimes desirable to display status information during a long-term operation. You can display status information by /// setting up an Internet status callback function that cannot be removed as long as any callbacks or any asynchronous functions /// are pending. /// /// /// After initiating InternetSetStatusCallback, the callback function can be accessed from within any WinINet function for /// monitoring time-intensive network operations. /// /// /// Note The callback function specified in the lpfnInternetCallback parameter will not be called on asynchronous operations /// for the request handle when the dwContext parameter of HttpOpenRequest is set to zero ( INTERNET_NO_CALLBACK), or the /// connection handle when the dwContext handle of InternetConnect is set to zero ( INTERNET_NO_CALLBACK). /// /// /// Like all other aspects of the WinINet API, this function cannot be safely called from within DllMain or the constructors and /// destructors of global objects. /// /// /// Note WinINet does not support server implementations. In addition, it should not be used from a service. For server /// implementations or services use Microsoft Windows HTTP Services (WinHTTP). /// /// // https://docs.microsoft.com/en-us/windows/win32/api/wininet/nf-wininet-internetsetstatuscallback void InternetSetStatusCallback( // HINTERNET hInternet, INTERNET_STATUS_CALLBACK lpfnInternetCallback ); [DllImport(Lib.WinInet, SetLastError = true, ExactSpelling = true)] [PInvokeData("wininet.h", MSDNShortId = "fe15627b-c77b-45c0-8ff6-02faa8512b57")] public static extern IntPtr InternetSetStatusCallback(HINTERNET hInternet, InternetStatusCallback lpfnInternetCallback); /// Formats a date and time according to the HTTP version 1.0 specification. /// Pointer to a SYSTEMTIME structure that contains the date and time to format. /// RFC format used. Currently, the only valid format is INTERNET_RFC1123_FORMAT. /// Pointer to a string buffer that receives the formatted date and time. The buffer should be of size INTERNET_RFC1123_BUFSIZE. /// Size of the lpszTime buffer, in bytes. /// Returns TRUE if the function succeeds, or FALSE otherwise. To get extended error information, call GetLastError. /// /// Note WinINet does not support server implementations. In addition, it should not be used from a service. For server /// implementations or services use Microsoft Windows HTTP Services (WinHTTP). /// // https://docs.microsoft.com/en-us/windows/win32/api/wininet/nf-wininet-internettimefromsystemtime BOOLAPI // InternetTimeFromSystemTime( const SYSTEMTIME *pst, DWORD dwRFC, LPSTR lpszTime, DWORD cbTime ); [DllImport(Lib.WinInet, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("wininet.h", MSDNShortId = "b52ba402-bad1-4005-b9d0-7630194272d1")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool InternetTimeFromSystemTime(in SYSTEMTIME pst, INTERNET_RFC dwRFC, StringBuilder lpszTime, uint cbTime); /// Converts an HTTP time/date string to a SYSTEMTIME structure. /// Pointer to a null-terminated string that specifies the date/time to be converted. /// Pointer to a SYSTEMTIME structure that receives the converted time. /// This parameter is reserved and must be 0. /// /// Returns TRUE if the string was converted, or FALSE otherwise. To get extended error information, call GetLastError. /// /// /// Note WinINet does not support server implementations. In addition, it should not be used from a service. For server /// implementations or services use Microsoft Windows HTTP Services (WinHTTP). /// // https://docs.microsoft.com/en-us/windows/win32/api/wininet/nf-wininet-internettimetosystemtime BOOLAPI InternetTimeToSystemTime( // LPCSTR lpszTime, SYSTEMTIME *pst, DWORD dwReserved ); [DllImport(Lib.WinInet, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("wininet.h", MSDNShortId = "fcfe99de-13b2-4e93-a978-f013ddae89f0")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool InternetTimeToSystemTime(string lpszTime, out SYSTEMTIME pst, uint dwReserved = 0); /// Unlocks a file that was locked using InternetLockRequestFile. /// Handle to a lock request that was returned by InternetLockRequestFile. /// Returns TRUE if successful, or FALSE otherwise. To get a specific error message, call GetLastError. /// /// Note WinINet does not support server implementations. In addition, it should not be used from a service. For server /// implementations or services use Microsoft Windows HTTP Services (WinHTTP). /// // https://docs.microsoft.com/en-us/windows/win32/api/wininet/nf-wininet-internetunlockrequestfile BOOLAPI // InternetUnlockRequestFile( HANDLE hLockRequestInfo ); [DllImport(Lib.WinInet, SetLastError = true, ExactSpelling = true)] [PInvokeData("wininet.h", MSDNShortId = "356f7277-66ef-450f-ab5a-0303d0b1d807")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool InternetUnlockRequestFile(HANDLE hLockRequestInfo); /// Writes data to an open Internet file. /// Handle returned from a previous call to FtpOpenFile or an HINTERNET handle sent by HttpSendRequestEx. /// Pointer to a buffer that contains the data to be written to the file. /// Number of bytes to be written to the file. /// /// Pointer to a variable that receives the number of bytes written to the file. InternetWriteFile sets this value to zero /// before doing any work or error checking. /// /// /// Returns TRUE if the function succeeds, or FALSE otherwise. To get extended error information, call GetLastError. An application /// can also use InternetGetLastResponseInfo when necessary. /// /// /// When the application is sending data, it must call InternetCloseHandle to end the data transfer. /// /// Like all other aspects of the WinINet API, this function cannot be safely called from within DllMain or the constructors and /// destructors of global objects. /// /// /// Note WinINet does not support server implementations. In addition, it should not be used from a service. For server /// implementations or services use Microsoft Windows HTTP Services (WinHTTP). /// /// // https://docs.microsoft.com/en-us/windows/win32/api/wininet/nf-wininet-internetwritefile BOOLAPI InternetWriteFile( HINTERNET // hFile, LPCVOID lpBuffer, DWORD dwNumberOfBytesToWrite, LPDWORD lpdwNumberOfBytesWritten ); [DllImport(Lib.WinInet, SetLastError = true, ExactSpelling = true)] [PInvokeData("wininet.h", MSDNShortId = "3bf8d4d8-9193-4aed-acf9-8d7207b332a5")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool InternetWriteFile(HINTERNET hFile, IntPtr lpBuffer, uint dwNumberOfBytesToWrite, out uint lpdwNumberOfBytesWritten); /// Writes data to an open Internet file. /// Handle returned from a previous call to FtpOpenFile or an HINTERNET handle sent by HttpSendRequestEx. /// Pointer to a buffer that contains the data to be written to the file. /// Number of bytes to be written to the file. /// /// Pointer to a variable that receives the number of bytes written to the file. InternetWriteFile sets this value to zero /// before doing any work or error checking. /// /// /// Returns TRUE if the function succeeds, or FALSE otherwise. To get extended error information, call GetLastError. An application /// can also use InternetGetLastResponseInfo when necessary. /// /// /// When the application is sending data, it must call InternetCloseHandle to end the data transfer. /// /// Like all other aspects of the WinINet API, this function cannot be safely called from within DllMain or the constructors and /// destructors of global objects. /// /// /// Note WinINet does not support server implementations. In addition, it should not be used from a service. For server /// implementations or services use Microsoft Windows HTTP Services (WinHTTP). /// /// // https://docs.microsoft.com/en-us/windows/win32/api/wininet/nf-wininet-internetwritefile BOOLAPI InternetWriteFile( HINTERNET // hFile, LPCVOID lpBuffer, DWORD dwNumberOfBytesToWrite, LPDWORD lpdwNumberOfBytesWritten ); [DllImport(Lib.WinInet, SetLastError = true, ExactSpelling = true)] [PInvokeData("wininet.h", MSDNShortId = "3bf8d4d8-9193-4aed-acf9-8d7207b332a5")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool InternetWriteFile(HINTERNET hFile, byte[] lpBuffer, int dwNumberOfBytesToWrite, out uint lpdwNumberOfBytesWritten); /// Retrieves the privacy settings for a given URLZONE and PrivacyType. /// A value of type DWORD that specifies the URLZONE for which privacy settings are being retrieved. /// A value of type DWORD that specifies the PrivacyType for which privacy settings are being retrieved. /// /// An LPDWORD that returns a pointer to a DWORD containing which of the PrivacyTemplates is in use for this dwZone /// and dwType. /// /// /// An LPWSTR that points to a buffer containing a LPCWSTR representing a string version of the pdwTemplate or a /// customized string if the pdwTemplate is set to PRIVACY_TEMPLATE_CUSTOM. See PrivacySetZonePreferenceW for a description /// of a customized privacy preferences string. /// /// /// An LPDWORD that contains the buffer length in characters. If the buffer length is not sufficient, /// PrivacyGetZonePreferenceW returns with this parameter set to the number of characters required and with a return value of ERROR_MORE_DATA. /// /// Returns zero if successful. Otherwise, one of the Error Messages defined in winerr.h is returned. /// /// These privacy settings for the Internet zone are found on the Privacy tab of the Internet Options dialog box. /// /// Like all other aspects of the WinINet API, this function cannot be safely called from within DllMain or the constructors and /// destructors of global objects. /// /// /// Note WinINet does not support server implementations. In addition, it should not be used from a service. For server /// implementations or services use Microsoft Windows HTTP Services (WinHTTP). /// /// // https://docs.microsoft.com/en-us/windows/win32/api/wininet/nf-wininet-privacygetzonepreferencew void PrivacyGetZonePreferenceW( // DWORD dwZone, DWORD dwType, LPDWORD pdwTemplate, LPWSTR pszBuffer, LPDWORD pdwBufferLength ); [DllImport(Lib.WinInet, SetLastError = false, ExactSpelling = true, CharSet = CharSet.Unicode)] [PInvokeData("wininet.h", MSDNShortId = "530a86a0-bb67-406a-be83-5f2b463a1aa1")] public static extern Win32Error PrivacyGetZonePreferenceW(URLZONE dwZone, PrivacyType dwType, out PrivacyTemplate pdwTemplate, StringBuilder pszBuffer, ref uint pdwBufferLength); /// Sets the privacy settings for a given URLZONE and PrivacyType. /// Value of type DWORD that specifies the URLZONEfor which privacy settings are being set. /// Value of type DWORD that specifies the PrivacyType for which privacy settings are being set. /// /// Value of type DWORD that specifies which of the privacy templates is to be used to set the privacy settings. /// /// /// If dwTemplate is set to PRIVACY_TEMPLATE_CUSTOM, this parameter is the string representation of the custom preferences. /// Otherwise, it should be set to NULL. A description of this string representation is included in the Remarks section. /// /// Returns zero if successful. Otherwise, one of the errors defined in winerr.h is returned. /// /// /// These privacy settings for the Internet zone are found on the Privacy tab of the Internet Options dialog box. /// /// /// Setting the privacy options for the URLZONE_INTERNET involves setting the privacy templates for both PrivacyTypes. The slider on /// the Privacy Menu in Internet Options only moves if privacy is set for both PrivacyTypes. /// /// /// Custom privacy preferences for a given URLZONE and PrivacyType can be set through the pszPreference parameter. The pszPreference /// parameter can contain a series of rules separated by white space describing the privacy preferences. It is important to note /// that the rules themselves cannot contain white space. The pszPreference has the following structure where there can be multiple /// logical rules: <signature> <logical-rule> <special-rule>. /// /// Currently, the signature must be set to IE6-P3PSettings/V1:. /// Logical rules have the following format: /<expression>=<decision>/. /// /// An expression is a Boolean statement composed of compact policy tokens using the operators & (logical AND) and ! (logical /// NOT). The compact policy token is case-sensitive. (For more information on Platform for Privacy Preferences (P3P) privacy /// policies and compact policy tokens, see the W3C: Platform for Privacy Preferences (P3P) Project specification.) The decision is /// a single lowercase character that defines the action to take on the cookie whose compact policy contains the specified token(s). /// The following table lists valid decision characters. /// /// /// /// Character /// Definition /// /// /// a /// Accept the cookie. /// /// /// p /// Prompt user to accept or deny the cookie. /// /// /// r /// Reject the cookie. /// /// /// l /// Leash the cookie (only send it in a first-party context). /// /// /// d /// Downgrade the cookie, if it is a persistent cookie, to a session cookie. /// /// /// /// Logical rules are evaluated in the order they are listed. The first logical-rule to be matched, if any, determines the cookie action. /// /// /// An empty expression is also allowed. If an expression is empty, the left side evaluates to true. This form of a logical-rule can /// be used at the end of a set of rules to catch all situations that did not fall into the other categories. /// /// The following examples show valid logical rules. /// /// Special rules are specified using the nopolicy, session, and always symbols. The nopolicy symbol is used to specify the action /// to taken when there is no compact policy. For example nopolicy=d specifies to downgrade all cookies without a compact policy to /// session cookies. The session symbol is used to specify the action to take on session cookies and can only be set to a. When /// session=a is specified, all session cookies are accepted regardless of the content of the compact policy. If this rule is not /// specified, session cookies are subject to the same rules as persistent cookies. Finally, the always symbol is used to specify to /// perform the same action for everything. For example, always=d specifies to deny all cookies regardless of the existence of a /// compact policy. Note that always=d is equivalent to /=d/. /// /// /// The following example shows a privacy preferences string that specifies to accept cookies for which the compact policy contains /// a FIN/CONi token pair, reject cookies with compact policies containing FIN/CON, FIN/CONo, FIN/CONa and GOV/PUB token pairs or a /// TEL token, and to prompt the user when a cookie's compact policy contains the UNR token. It also specifies to downgrade cookies /// without a compact policy to session cookies and to accept all cookies that do not match one of the given rules. Note that the /// first rule that evaluates to true determines the cookie action. /// /// /// Like all other aspects of the WinINet API, this function cannot be safely called from within DllMain or the constructors and /// destructors of global objects. /// /// /// Note WinINet does not support server implementations. In addition, it should not be used from a service. For server /// implementations or services use Microsoft Windows HTTP Services (WinHTTP). /// /// // https://docs.microsoft.com/en-us/windows/win32/api/wininet/nf-wininet-privacysetzonepreferencew void PrivacySetZonePreferenceW( // DWORD dwZone, DWORD dwType, DWORD dwTemplate, LPCWSTR pszPreference ); [DllImport(Lib.WinInet, SetLastError = false, ExactSpelling = true, CharSet = CharSet.Unicode)] [PInvokeData("wininet.h", MSDNShortId = "29c8dbc0-052e-40f4-a036-cb647d920055")] public static extern Win32Error PrivacySetZonePreferenceW(URLZONE dwZone, PrivacyType dwType, PrivacyTemplate dwTemplate, [Optional] string pszPreference); /// Reads the cached data from a stream that has been opened using the RetrieveUrlCacheEntryStream function. /// Handle that was returned by the RetrieveUrlCacheEntryStream function. /// Offset to be read from. /// Pointer to a buffer that receives the data. /// /// Pointer to a variable that specifies the size of the lpBuffer buffer, in bytes. When the function returns, the variable contains /// the number of bytes copied to the buffer, or the required size of the buffer, in bytes. /// /// This parameter is reserved and must be 0. /// Returns TRUE if successful, or FALSE otherwise. To get extended error information, call GetLastError. /// /// /// If the buffer size is not sufficient, GetLastError returns ERROR_INSUFFICIENT_BUFFER and sets lpdwLen to the size necessary to /// contain all the information. /// /// /// Like all other aspects of the WinINet API, this function cannot be safely called from within DllMain or the constructors and /// destructors of global objects. /// /// /// Note WinINet does not support server implementations. In addition, it should not be used from a service. For server /// implementations or services use Microsoft Windows HTTP Services (WinHTTP). /// /// // https://docs.microsoft.com/en-us/windows/win32/api/wininet/nf-wininet-readurlcacheentrystream BOOLAPI ReadUrlCacheEntryStream( // HANDLE hUrlCacheStream, DWORD dwLocation, LPVOID lpBuffer, LPDWORD lpdwLen, DWORD Reserved ); [DllImport(Lib.WinInet, SetLastError = true, ExactSpelling = true)] [PInvokeData("wininet.h", MSDNShortId = "8cfd0c64-25ca-4f08-b9b3-2743ded18030")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool ReadUrlCacheEntryStream(HCACHEENTRYSTREAM hUrlCacheStream, uint dwLocation, IntPtr lpBuffer, ref uint lpdwLen, uint Reserved = 0); /// The ResumeSuspendedDownload function resumes a request that is suspended by a user interface dialog box. /// Handle of the request that is suspended by a user interface dialog box. /// The error result returned from InternetErrorDlg, or zero if a different dialog is invoked. /// Returns TRUE if successful; otherwise FALSE. Call GetLastError for extended error information. /// /// /// Applications that use WinINet functions asynchronously can call ResumeSuspendedDownload to resume a request that is /// suspended by a user interface dialog box. /// /// /// For example, call ResumeSuspendedDownload after a call to InternetErrorDlg, or in an InternetStatusCallback function when /// the lpvStatusInformation parameter equals INTERNET_STATUS_USER_INPUT_REQUIRED. The following code example shows you how /// to use the ResumeSuspendedDownload function in a callback. /// /// /// Like all other aspects of the WinINet API, this function cannot be safely called from within DllMain or the constructors and /// destructors of global objects. /// /// /// Note WinINet does not support server implementations. In addition, it should not be used from a service. For server /// implementations or services use Microsoft Windows HTTP Services (WinHTTP). /// /// Examples /// // https://docs.microsoft.com/en-us/windows/win32/api/wininet/nf-wininet-resumesuspendeddownload BOOLAPI ResumeSuspendedDownload( // HINTERNET hRequest, DWORD dwResultCode ); [DllImport(Lib.WinInet, SetLastError = true, ExactSpelling = true)] [PInvokeData("wininet.h", MSDNShortId = "72b5511a-872d-4058-9f38-9b1bdf6784c3")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool ResumeSuspendedDownload(HINTERNET hRequest, Win32Error dwResultCode); /// Locks the cache entry file associated with the specified URL. /// /// Pointer to a string that contains the URL of the resource associated with the cache entry. This must be a unique name. The name /// string should not contain any escape characters. /// /// /// Pointer to a cache entry information buffer. If the buffer is not sufficient, this function returns ERROR_INSUFFICIENT_BUFFER /// and sets lpdwCacheEntryInfoBufferSize to the number of bytes required. /// /// /// Pointer to an unsigned long integer variable that specifies the size of the lpCacheEntryInfo buffer, in bytes. When the function /// returns, the variable contains the size, in bytes, of the actual buffer used or the number of bytes required to retrieve the /// cache entry file. The caller should check the return value in this parameter. If the return size is less than or equal to the /// size passed in, all the relevant data has been returned. /// /// This parameter is reserved and must be 0. /// /// /// Returns TRUE if successful, or FALSE otherwise. To get extended error information, call GetLastError. Possible /// error values include: /// /// /// /// Return code /// Description /// /// /// ERROR_FILE_NOT_FOUND /// The cache entry specified by the source name is not found in the cache storage. /// /// /// ERROR_INSUFFICIENT_BUFFER /// /// The size of the lpCacheEntryInfo buffer as specified by lpdwCacheEntryInfoBufferSize is not sufficient to contain all the /// information. The value returned in lpdwCacheEntryInfoBufferSize indicates the buffer size necessary to get all the information. /// /// /// /// /// /// /// RetrieveUrlCacheEntryFile does not do any URL parsing, so a URL containing an anchor (#) will not be found in the cache, /// even if the resource is cached. For example, if the URL http://adatum.com/example.htm#sample was passed, the function would /// return ERROR_FILE_NOT_FOUND even if http://adatum.com/example.htm is in the cache. /// /// /// The file is locked for the caller when it is retrieved; the caller should unlock the file after the caller is finished with the /// file. The cache manager automatically unlocks the files after a certain interval. While the file is locked, the cache manager /// will not remove the file from the cache. It is important to note that this function may or may not perform efficiently, /// depending on the internal implementation of the cache. For instance, if the URL data is stored in a packed file that contains /// data for other URLs, the cache will make a copy of the data to a file in a temporary directory maintained by the cache. The /// cache will eventually delete the copy. It is recommended that this function be used only in situations where a file name is /// needed to launch an application. RetrieveUrlCacheEntryStream and associated stream functions should be used in most cases. /// /// /// Like all other aspects of the WinINet API, this function cannot be safely called from within DllMain or the constructors and /// destructors of global objects. /// /// /// Note WinINet does not support server implementations. In addition, it should not be used from a service. For server /// implementations or services use Microsoft Windows HTTP Services (WinHTTP). /// /// // https://docs.microsoft.com/en-us/windows/win32/api/wininet/nf-wininet-retrieveurlcacheentryfilea BOOLAPI // RetrieveUrlCacheEntryFileA( LPCSTR lpszUrlName, LPINTERNET_CACHE_ENTRY_INFOA lpCacheEntryInfo, LPDWORD lpcbCacheEntryInfo, DWORD // dwReserved ); [DllImport(Lib.WinInet, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("wininet.h", MSDNShortId = "eb311b8d-560d-4742-af4c-b5afe660c8e5")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool RetrieveUrlCacheEntryFile(string lpszUrlName, IntPtr lpCacheEntryInfo, ref uint lpcbCacheEntryInfo, uint dwReserved = 0); /// Provides the most efficient and implementation-independent way to access the cache data. /// /// Pointer to a null-terminated string that contains the source name of the cache entry. This must be a unique name. The name /// string should not contain any escape characters. /// /// /// Pointer to an INTERNET_CACHE_ENTRY_INFO structure that receives information about the cache entry. /// /// /// Pointer to a variable that specifies the size, in bytes, of the lpCacheEntryInfo buffer. When the function returns, the variable /// receives the number of bytes copied to the buffer or the required size, in bytes, of the buffer. Note that this buffer size must /// accommodate both the INTERNET_CACHE_ENTRY_INFO structure and the associated strings that are stored immediately following it. /// /// /// Whether the stream is open for random access. Set the flag to TRUE to open the stream for random access. /// /// This parameter is reserved and must be 0. /// /// /// If the function succeeds, the function returns a valid handle for use in the ReadUrlCacheEntryStream and /// UnlockUrlCacheEntryStream functions. /// /// If the function fails, it returns NULL. To get extended error information, call GetLastError. /// Possible error values include the following. /// /// /// Return code /// Description /// /// /// ERROR_FILE_NOT_FOUND /// The cache entry specified by the source name is not found in the cache storage. /// /// /// ERROR_INSUFFICIENT_BUFFER /// /// The size of lpCacheEntryInfo as specified by lpdwCacheEntryInfoBufferSize is not sufficient to contain all the information. The /// value returned in lpdwCacheEntryInfoBufferSize indicates the buffer size necessary to contain all the information. /// /// /// /// /// /// /// RetrieveUrlCacheEntryStream does not do any URL parsing, so a URL containing an anchor (#) will not be found in the /// cache, even if the resource is cached. For example, if the URL http://adatum.com/example.htm#sample is passed, the function /// returns ERROR_FILE_NOT_FOUND even if http://adatum.com/example.htm is in the cache. /// /// /// Cache clients that do not need URL data in the form of a file should use this function to access the data for a particular URL. /// /// /// Like all other aspects of the WinINet API, this function cannot be safely called from within DllMain or the constructors and /// destructors of global objects. /// /// /// Note WinINet does not support server implementations. In addition, it should not be used from a service. For server /// implementations or services use Microsoft Windows HTTP Services (WinHTTP). /// /// // https://docs.microsoft.com/en-us/windows/win32/api/wininet/nf-wininet-retrieveurlcacheentrystreama void // RetrieveUrlCacheEntryStreamA( LPCSTR lpszUrlName, LPINTERNET_CACHE_ENTRY_INFOA lpCacheEntryInfo, LPDWORD lpcbCacheEntryInfo, BOOL // fRandomRead, DWORD dwReserved ); [DllImport(Lib.WinInet, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("wininet.h", MSDNShortId = "0414efb0-d91b-46f0-9fee-0b69ef823029")] public static extern SafeHCACHEENTRYSTREAM RetrieveUrlCacheEntryStream(string lpszUrlName, IntPtr lpCacheEntryInfo, ref uint lpcbCacheEntryInfo, [MarshalAs(UnmanagedType.Bool)] bool fRandomRead, uint dwReserved = 0); /// Adds entries to or removes entries from a cache group. /// Pointer to a null-terminated string value that specifies the URL of the cached resource. /// /// Determines whether the entry is added to or removed from a cache group. This parameter can be one of the following values. /// /// /// Value /// Meaning /// /// /// INTERNET_CACHE_GROUP_ADD /// Adds the cache entry to the cache group. /// /// /// INTERNET_CACHE_GROUP_REMOVE /// Removes the entry from the cache group. /// /// /// /// Identifier of the cache group that the entry will be added to or removed from. /// This parameter is reserved and must be NULL. /// This parameter is reserved and must be 0. /// This parameter is reserved and must be NULL. /// Returns TRUE if successful, or FALSE otherwise. /// /// A cache entry can belong to more than one cache group. /// /// Like all other aspects of the WinINet API, this function cannot be safely called from within DllMain or the constructors and /// destructors of global objects. /// /// /// Note WinINet does not support server implementations. In addition, it should not be used from a service. For server /// implementations or services use Microsoft Windows HTTP Services (WinHTTP). /// /// // https://docs.microsoft.com/en-us/windows/win32/api/wininet/nf-wininet-seturlcacheentrygroup BOOLAPI SetUrlCacheEntryGroup( LPCSTR // lpszUrlName, DWORD dwFlags, GROUPID GroupId, LPBYTE pbGroupAttributes, DWORD cbGroupAttributes, LPVOID lpReserved ); [DllImport(Lib.WinInet, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("wininet.h", MSDNShortId = "b39a96ac-c5b5-4b02-88e2-298a037be25f")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool SetUrlCacheEntryGroup(string lpszUrlName, INTERNET_CACHE_GROUP dwFlags, long GroupId, IntPtr pbGroupAttributes = default, uint cbGroupAttributes = 0, IntPtr lpReserved = default); /// Sets the specified members of the INTERNET_CACHE_ENTRY_INFO structure. /// /// Pointer to a null-terminated string that specifies the name of the cache entry. The name string should not contain any escape characters. /// /// /// Pointer to an INTERNET_CACHE_ENTRY_INFO structure containing the values to be assigned to the cache entry designated by lpszUrlName. /// /// /// Indicates the members that are to be set. This parameter can be a combination of the following values. /// /// /// Value /// Meaning /// /// /// CACHE_ENTRY_ACCTIME_FC /// Sets the last access time. /// /// /// CACHE_ENTRY_ATTRIBUTE_FC /// Sets the cache entry type. /// /// /// CACHE_ENTRY_EXEMPT_DELTA_FC /// Sets the exempt delta. /// /// /// CACHE_ENTRY_EXPTIME_FC /// Sets the expire time. /// /// /// CACHE_ENTRY_HEADERINFO_FC /// Not currently implemented. /// /// /// CACHE_ENTRY_HITRATE_FC /// Sets the hit rate. /// /// /// CACHE_ENTRY_MODTIME_FC /// Sets the last modified time. /// /// /// CACHE_ENTRY_SYNCTIME_FC /// Sets the last sync time. /// /// /// /// /// /// Returns TRUE if successful, or FALSE otherwise. To get extended error information, call GetLastError. Possible error values /// include the following. /// /// /// /// Return code /// Description /// /// /// ERROR_FILE_NOT_FOUND /// The specified cache entry is not found in the cache. /// /// /// ERROR_INVALID_PARAMETER /// The value(s) to be set is invalid. /// /// /// /// /// Note WinINet does not support server implementations. In addition, it should not be used from a service. For server /// implementations or services use Microsoft Windows HTTP Services (WinHTTP). /// // https://docs.microsoft.com/en-us/windows/win32/api/wininet/nf-wininet-seturlcacheentryinfow BOOLAPI SetUrlCacheEntryInfoW( // LPCWSTR lpszUrlName, LPINTERNET_CACHE_ENTRY_INFOW lpCacheEntryInfo, DWORD dwFieldControl ); [DllImport(Lib.WinInet, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("wininet.h", MSDNShortId = "71f6e1a3-09ce-4576-9480-1270f343db39")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool SetUrlCacheEntryInfo(string lpszUrlName, in INTERNET_CACHE_ENTRY_INFO lpCacheEntryInfo, CACHE_ENTRY_FC dwFieldControl); /// Unlocks the cache entry that was locked while the file was retrieved for use from the cache. /// /// Pointer to a null-terminated string that specifies the source name of the cache entry that is being unlocked. The name /// string should not contain any escape characters. /// /// This parameter is reserved and must be 0. /// /// Returns TRUE if successful, or FALSE otherwise. To get extended error information, call GetLastError. /// ERROR_FILE_NOT_FOUND indicates that the cache entry specified by the source name is not found in the cache storage. /// /// /// The application should not access the file after calling this function. /// When this function returns, the cache manager is free to delete the cache entry. /// /// Like all other aspects of the WinINet API, this function cannot be safely called from within DllMain or the constructors and /// destructors of global objects. /// /// /// Note WinINet does not support server implementations. In addition, it should not be used from a service. For server /// implementations or services use Microsoft Windows HTTP Services (WinHTTP). /// /// // https://docs.microsoft.com/en-us/windows/win32/api/wininet/nf-wininet-unlockurlcacheentryfile BOOLAPI UnlockUrlCacheEntryFile( // LPCSTR lpszUrlName, DWORD dwReserved ); [DllImport(Lib.WinInet, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("wininet.h", MSDNShortId = "ccc650dc-1759-4438-85d5-539c71d21a74")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool UnlockUrlCacheEntryFile(string lpszUrlName, uint dwReserved = 0); /// Closes the stream that has been retrieved using the RetrieveUrlCacheEntryStream function. /// Handle that was returned by the RetrieveUrlCacheEntryStream function. /// This parameter is reserved and must be NULL. /// Returns TRUE if successful, or FALSE otherwise. To get extended error information, call GetLastError. /// /// Note WinINet does not support server implementations. In addition, it should not be used from a service. For server /// implementations or services use Microsoft Windows HTTP Services (WinHTTP). /// // https://docs.microsoft.com/en-us/windows/win32/api/wininet/nf-wininet-unlockurlcacheentrystream BOOLAPI // UnlockUrlCacheEntryStream( HANDLE hUrlCacheStream, DWORD Reserved ); [DllImport(Lib.WinInet, SetLastError = true, ExactSpelling = true)] [PInvokeData("wininet.h", MSDNShortId = "9fcc257e-732c-4545-a81b-7db20a98e497")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool UnlockUrlCacheEntryStream(HANDLE hUrlCacheStream, uint Reserved = 0); [DllImport("inetcpl.cpl", SetLastError = true)] private static extern int LaunchInternetControlPanel(HWND hWnd); /// /// /// [The GOPHER_ATTRIBUTE_TYPE structure is available for use in the operating systems specified in the Requirements section.] /// /// Contains the relevant information of a single Gopher attribute for an object. /// /// /// Note WinINet does not support server implementations. In addition, it should not be used from a service. For server /// implementations or services use Microsoft Windows HTTP Services (WinHTTP). /// // https://docs.microsoft.com/en-us/windows/win32/api/wininet/ns-wininet-gopher_attribute_type typedef struct { DWORD CategoryId; // DWORD AttributeId; union { GOPHER_ADMIN_ATTRIBUTE_TYPE Admin; GOPHER_MOD_DATE_ATTRIBUTE_TYPE ModDate; GOPHER_TTL_ATTRIBUTE_TYPE // Ttl; GOPHER_SCORE_ATTRIBUTE_TYPE Score; GOPHER_SCORE_RANGE_ATTRIBUTE_TYPE ScoreRange; GOPHER_SITE_ATTRIBUTE_TYPE Site; // GOPHER_ORGANIZATION_ATTRIBUTE_TYPE Organization; GOPHER_LOCATION_ATTRIBUTE_TYPE Location; // GOPHER_GEOGRAPHICAL_LOCATION_ATTRIBUTE_TYPE GeographicalLocation; GOPHER_TIMEZONE_ATTRIBUTE_TYPE TimeZone; // GOPHER_PROVIDER_ATTRIBUTE_TYPE Provider; GOPHER_VERSION_ATTRIBUTE_TYPE Version; GOPHER_ABSTRACT_ATTRIBUTE_TYPE Abstract; // GOPHER_VIEW_ATTRIBUTE_TYPE View; GOPHER_VERONICA_ATTRIBUTE_TYPE Veronica; GOPHER_ASK_ATTRIBUTE_TYPE Ask; // GOPHER_UNKNOWN_ATTRIBUTE_TYPE Unknown; } AttributeType; } GOPHER_ATTRIBUTE_TYPE, *LPGOPHER_ATTRIBUTE_TYPE; [PInvokeData("wininet.h", MSDNShortId = "01daae8c-9080-4a8d-9f73-3e364ca868fe")] [StructLayout(LayoutKind.Sequential)] public struct GOPHER_ATTRIBUTE_TYPE { /// /// Name of the Gopher category for the attribute. The possible values include: /// GOPHER_CATEGORY_ID_ABSTRACT /// GOPHER_CATEGORY_ID_ADMIN /// GOPHER_CATEGORY_ID_ALL /// GOPHER_CATEGORY_ID_INFO /// GOPHER_CATEGORY_ID_UNKNOWN /// GOPHER_CATEGORY_ID_VERONICA /// GOPHER_CATEGORY_ID_VIEWS /// public GOPHER_CATEGORY_ID CategoryId; /// /// Attribute type. The possible values include: /// GOPHER_ATTRIBUTE_ID_ABSTRACT /// GOPHER_ATTRIBUTE_ID_ADMIN /// GOPHER_ATTRIBUTE_ID_GEOG /// GOPHER_ATTRIBUTE_ID_LOCATION /// GOPHER_ATTRIBUTE_ID_MOD_DATE /// GOPHER_ATTRIBUTE_ID_ORG /// GOPHER_ATTRIBUTE_ID_PROVIDER /// GOPHER_ATTRIBUTE_ID_RANGE /// GOPHER_ATTRIBUTE_ID_SCORE /// GOPHER_ATTRIBUTE_ID_SITE /// GOPHER_ATTRIBUTE_ID_TIMEZONE /// GOPHER_ATTRIBUTE_ID_TREEWALK /// GOPHER_ATTRIBUTE_ID_TTL /// GOPHER_ATTRIBUTE_ID_UNKNOWN /// GOPHER_ATTRIBUTE_ID_VERSION /// GOPHER_ATTRIBUTE_ID_VIEW /// public GOPHER_ATTRIBUTE_ID AttributeId; /// /// Data for the Gopher attribute. The specific structure depends on the AttributeId member. The definitions of these /// data structures are available in WinInet.h. /// public ATTRIBUTETYPE AttributeType; /// /// Data for the Gopher attribute. The specific structure depends on the AttributeId member. The definitions of these /// data structures are available in WinInet.h. /// [StructLayout(LayoutKind.Explicit)] public struct ATTRIBUTETYPE { /// [FieldOffset(0)] public GOPHER_ADMIN_ATTRIBUTE_TYPE Admin; /// [FieldOffset(0)] public GOPHER_MOD_DATE_ATTRIBUTE_TYPE ModDate; /// [FieldOffset(0)] public GOPHER_TTL_ATTRIBUTE_TYPE Ttl; /// [FieldOffset(0)] public GOPHER_SCORE_ATTRIBUTE_TYPE Score; /// [FieldOffset(0)] public GOPHER_SCORE_RANGE_ATTRIBUTE_TYPE ScoreRange; /// [FieldOffset(0)] public GOPHER_SITE_ATTRIBUTE_TYPE Site; /// [FieldOffset(0)] public GOPHER_ORGANIZATION_ATTRIBUTE_TYPE Organization; /// [FieldOffset(0)] public GOPHER_LOCATION_ATTRIBUTE_TYPE Location; /// [FieldOffset(0)] public GOPHER_GEOGRAPHICAL_LOCATION_ATTRIBUTE_TYPE GeographicalLocation; /// [FieldOffset(0)] public GOPHER_TIMEZONE_ATTRIBUTE_TYPE TimeZone; /// [FieldOffset(0)] public GOPHER_PROVIDER_ATTRIBUTE_TYPE Provider; /// [FieldOffset(0)] public GOPHER_VERSION_ATTRIBUTE_TYPE Version; /// [FieldOffset(0)] public GOPHER_ABSTRACT_ATTRIBUTE_TYPE Abstract; /// [FieldOffset(0)] public GOPHER_VIEW_ATTRIBUTE_TYPE View; /// [FieldOffset(0)] public GOPHER_VERONICA_ATTRIBUTE_TYPE Veronica; /// [FieldOffset(0)] public GOPHER_ASK_ATTRIBUTE_TYPE Ask; /// [FieldOffset(0)] public GOPHER_UNKNOWN_ATTRIBUTE_TYPE Unknown; /// [StructLayout(LayoutKind.Sequential)] public struct GOPHER_ADMIN_ATTRIBUTE_TYPE { /// public StrPtrAuto Comment; /// public StrPtrAuto EmailAddress; } /// [StructLayout(LayoutKind.Sequential)] public struct GOPHER_MOD_DATE_ATTRIBUTE_TYPE { /// public FILETIME DateAndTime; } /// [StructLayout(LayoutKind.Sequential)] public struct GOPHER_TTL_ATTRIBUTE_TYPE { /// public uint Ttl; } /// [StructLayout(LayoutKind.Sequential)] public struct GOPHER_SCORE_ATTRIBUTE_TYPE { /// public int Score; } /// [StructLayout(LayoutKind.Sequential)] public struct GOPHER_SCORE_RANGE_ATTRIBUTE_TYPE { /// public int LowerBound; /// public int UpperBound; } /// [StructLayout(LayoutKind.Sequential)] public struct GOPHER_SITE_ATTRIBUTE_TYPE { /// public StrPtrAuto Site; } /// [StructLayout(LayoutKind.Sequential)] public struct GOPHER_ORGANIZATION_ATTRIBUTE_TYPE { /// public StrPtrAuto Organization; } /// [StructLayout(LayoutKind.Sequential)] public struct GOPHER_LOCATION_ATTRIBUTE_TYPE { /// public StrPtrAuto Location; } /// [StructLayout(LayoutKind.Sequential)] public struct GOPHER_GEOGRAPHICAL_LOCATION_ATTRIBUTE_TYPE { /// public int DegreesNorth; /// public int MinutesNorth; /// public int SecondsNorth; /// public int DegreesEast; /// public int MinutesEast; /// public int SecondsEast; } /// [StructLayout(LayoutKind.Sequential)] public struct GOPHER_TIMEZONE_ATTRIBUTE_TYPE { /// public int Zone; } /// [StructLayout(LayoutKind.Sequential)] public struct GOPHER_PROVIDER_ATTRIBUTE_TYPE { /// public StrPtrAuto Provider; } /// [StructLayout(LayoutKind.Sequential)] public struct GOPHER_VERSION_ATTRIBUTE_TYPE { /// public StrPtrAuto Version; } /// [StructLayout(LayoutKind.Sequential)] public struct GOPHER_ABSTRACT_ATTRIBUTE_TYPE { /// public StrPtrAuto ShortAbstract; /// public StrPtrAuto AbstractFile; } /// [StructLayout(LayoutKind.Sequential)] public struct GOPHER_VIEW_ATTRIBUTE_TYPE { /// public StrPtrAuto ContentType; /// public StrPtrAuto Language; /// public uint Size; } /// [StructLayout(LayoutKind.Sequential)] public struct GOPHER_VERONICA_ATTRIBUTE_TYPE { /// [MarshalAs(UnmanagedType.Bool)] public bool TreeWalk; } /// [StructLayout(LayoutKind.Sequential)] public struct GOPHER_ASK_ATTRIBUTE_TYPE { /// public StrPtrAuto QuestionType; /// public StrPtrAuto QuestionText; } /// [StructLayout(LayoutKind.Sequential)] public struct GOPHER_UNKNOWN_ATTRIBUTE_TYPE { /// public StrPtrAuto Text; } } } /// /// [The GOPHER_FIND_DATA structure is available for use in the operating systems specified in the Requirements section.] /// Contains information retrieved by the GopherFindFirstFile and InternetFindNextFile functions. /// /// /// Note WinINet does not support server implementations. In addition, it should not be used from a service. For server /// implementations or services use Microsoft Windows HTTP Services (WinHTTP). /// // https://docs.microsoft.com/en-us/windows/win32/api/wininet/ns-wininet-gopher_find_dataa typedef struct { CHAR // DisplayString[MAX_GOPHER_DISPLAY_TEXT + 1]; DWORD GopherType; DWORD SizeLow; DWORD SizeHigh; FILETIME LastModificationTime; CHAR // Locator[MAX_GOPHER_LOCATOR_LENGTH + 1]; } GOPHER_FIND_DATAA, *LPGOPHER_FIND_DATAA; [PInvokeData("wininet.h", MSDNShortId = "53bcba70-2d6a-465a-86ec-4b11b1474ee1")] [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] public struct GOPHER_FIND_DATA { /// Friendly name of an object. An application can display this string to allow the user to select the object. [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 129)] public string DisplayString; /// /// Describes the item returned. This parameter can be one of the following values. /// /// /// Value /// Meaning /// /// /// GOPHER_TYPE_ASK /// Ask+ item. /// /// /// GOPHER_TYPE_BINARY /// Binary file. /// /// /// GOPHER_TYPE_BITMAP /// Bitmap file. /// /// /// GOPHER_TYPE_CALENDAR /// Calendar file. /// /// /// GOPHER_TYPE_CSO /// CSO telephone book server. /// /// /// GOPHER_TYPE_DIRECTORY /// Directory of additional Gopher items. /// /// /// GOPHER_TYPE_DOS_ARCHIVE /// MS-DOS archive file. /// /// /// GOPHER_TYPE_ERROR /// Indicator of an error condition. /// /// /// GOPHER_TYPE_GIF /// GIF graphics file. /// /// /// GOPHER_TYPE_GOPHER_PLUS /// Gopher+ item. /// /// /// GOPHER_TYPE_HTML /// HTML document. /// /// /// GOPHER_TYPE_IMAGE /// Image file. /// /// /// GOPHER_TYPE_INDEX_SERVER /// Index server. /// /// /// GOPHER_TYPE_INLINE /// Inline file. /// /// /// GOPHER_TYPE_MAC_BINHEX /// Macintosh file in BINHEX format. /// /// /// GOPHER_TYPE_MOVIE /// Movie file. /// /// /// GOPHER_TYPE_PDF /// PDF file. /// /// /// GOPHER_TYPE_REDUNDANT /// /// Indicator of a duplicated server. The information contained within is a duplicate of the primary server. The primary server /// is defined as the last directory entry that did not have a GOPHER_TYPE_REDUNDANT type. /// /// /// /// GOPHER_TYPE_SOUND /// Sound file. /// /// /// GOPHER_TYPE_TELNET /// Telnet server. /// /// /// GOPHER_TYPE_TEXT_FILE /// ASCII text file. /// /// /// GOPHER_TYPE_TN3270 /// TN3270 server. /// /// /// GOPHER_TYPE_UNIX_UUENCODED /// UUENCODED file. /// /// /// GOPHER_TYPE_UNKNOWN /// Item type is unknown. /// /// /// public GOPHER_TYPE GopherType; /// Low 32 bits of the file size. public uint SizeLow; /// High 32 bits of the file size. public uint SizeHigh; /// FILETIME structure that contains the time when the file was last modified. public FILETIME LastModificationTime; /// File locator. An application can pass the locator string to GopherOpenFile or GopherFindFirstFile. [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 654)] public string Locator; } /// Provides a handle to a cache entry sream. [StructLayout(LayoutKind.Sequential)] public struct HCACHEENTRYSTREAM : IHandle { private IntPtr handle; /// Initializes a new instance of the struct. /// An object that represents the pre-existing handle to use. public HCACHEENTRYSTREAM(IntPtr preexistingHandle) => handle = preexistingHandle; /// Returns an invalid handle by instantiating a object with . public static HCACHEENTRYSTREAM NULL => new HCACHEENTRYSTREAM(IntPtr.Zero); /// Gets a value indicating whether this instance is a null handle. public bool IsNull => handle == IntPtr.Zero; /// Performs an explicit conversion from to . /// The handle. /// The result of the conversion. public static explicit operator IntPtr(HCACHEENTRYSTREAM h) => h.handle; /// Performs an implicit conversion from to . /// The pointer to a handle. /// The result of the conversion. public static implicit operator HCACHEENTRYSTREAM(IntPtr h) => new HCACHEENTRYSTREAM(h); /// Implements the operator !=. /// The first handle. /// The second handle. /// The result of the operator. public static bool operator !=(HCACHEENTRYSTREAM h1, HCACHEENTRYSTREAM h2) => !(h1 == h2); /// Implements the operator ==. /// The first handle. /// The second handle. /// The result of the operator. public static bool operator ==(HCACHEENTRYSTREAM h1, HCACHEENTRYSTREAM h2) => h1.Equals(h2); /// public override bool Equals(object obj) => obj is HCACHEENTRYSTREAM h ? handle == h.handle : false; /// public override int GetHashCode() => handle.GetHashCode(); /// public IntPtr DangerousGetHandle() => handle; } /// Provides a handle to a url cache enumeration. [StructLayout(LayoutKind.Sequential)] public struct HFINDCACHE : IHandle { private readonly IntPtr handle; /// Initializes a new instance of the struct. /// An object that represents the pre-existing handle to use. public HFINDCACHE(IntPtr preexistingHandle) => handle = preexistingHandle; /// Returns an invalid handle by instantiating a object with . public static HFINDCACHE NULL => new HFINDCACHE(IntPtr.Zero); /// Gets a value indicating whether this instance is a null handle. public bool IsNull => handle == IntPtr.Zero; /// Performs an explicit conversion from to . /// The handle. /// The result of the conversion. public static explicit operator IntPtr(HFINDCACHE h) => h.handle; /// Performs an implicit conversion from to . /// The pointer to a handle. /// The result of the conversion. public static implicit operator HFINDCACHE(IntPtr h) => new HFINDCACHE(h); /// Implements the operator !=. /// The first handle. /// The second handle. /// The result of the operator. public static bool operator !=(HFINDCACHE h1, HFINDCACHE h2) => !(h1 == h2); /// Implements the operator ==. /// The first handle. /// The second handle. /// The result of the operator. public static bool operator ==(HFINDCACHE h1, HFINDCACHE h2) => h1.Equals(h2); /// public override bool Equals(object obj) => obj is HFINDCACHE h ? handle == h.handle : false; /// public override int GetHashCode() => handle.GetHashCode(); /// public IntPtr DangerousGetHandle() => handle; } /// Provides a handle to an internet connection. [StructLayout(LayoutKind.Sequential)] public struct HINTERNET : IHandle { private readonly IntPtr handle; /// Initializes a new instance of the struct. /// An object that represents the pre-existing handle to use. public HINTERNET(IntPtr preexistingHandle) => handle = preexistingHandle; /// Returns an invalid handle by instantiating a object with . public static HINTERNET NULL => new HINTERNET(IntPtr.Zero); /// Gets a value indicating whether this instance is a null handle. public bool IsNull => handle == IntPtr.Zero; /// Performs an explicit conversion from to . /// The handle. /// The result of the conversion. public static explicit operator IntPtr(HINTERNET h) => h.handle; /// Performs an implicit conversion from to . /// The pointer to a handle. /// The result of the conversion. public static implicit operator HINTERNET(IntPtr h) => new HINTERNET(h); /// Implements the operator !=. /// The first handle. /// The second handle. /// The result of the operator. public static bool operator !=(HINTERNET h1, HINTERNET h2) => !(h1 == h2); /// Implements the operator ==. /// The first handle. /// The second handle. /// The result of the operator. public static bool operator ==(HINTERNET h1, HINTERNET h2) => h1.Equals(h2); /// public override bool Equals(object obj) => obj is HINTERNET h ? handle == h.handle : false; /// public override int GetHashCode() => handle.GetHashCode(); /// public IntPtr DangerousGetHandle() => handle; } /// Contains the notification data for an authentication request. /// /// WinINet does not support server implementations. In addition, it should not be used from a service. For server /// implementations or services use Microsoft Windows HTTP Services (WinHTTP). /// // https://docs.microsoft.com/en-us/windows/win32/api/wininet/ns-wininet-internet_auth_notify_data typedef struct { DWORD cbStruct; // DWORD dwOptions; PFN_AUTH_NOTIFY pfnNotify; DWORD_PTR dwContext; } INTERNET_AUTH_NOTIFY_DATA; [PInvokeData("wininet.h", MSDNShortId = "d6f36cf7-7a54-4890-aa27-ffb40997cfd6")] [StructLayout(LayoutKind.Sequential)] public struct INTERNET_AUTH_NOTIFY_DATA { /// Size of the structure, in bytes. public uint cbStruct; /// Reserved. Must be 0. public uint dwOptions; /// Notification callback to retry InternetErrorDlg. public InternetAuthNotifyCallback pfnNotify; /// /// Pointer to a variable that contains an application-defined value used to identify the application context to pass to the /// notification function. /// public IntPtr dwContext; /// The default instance of INTERNET_AUTH_NOTIFY_DATA with cbStruct set. public static readonly INTERNET_AUTH_NOTIFY_DATA Default = new INTERNET_AUTH_NOTIFY_DATA { cbStruct = (uint)Marshal.SizeOf(typeof(INTERNET_AUTH_NOTIFY_DATA)) }; } /// Contains both the data and header information. /// /// Note WinINet does not support server implementations. In addition, it should not be used from a service. For server /// implementations or services use Microsoft Windows HTTP Services (WinHTTP). /// // https://docs.microsoft.com/en-us/windows/win32/api/wininet/ns-wininet-internet_buffersa typedef struct _INTERNET_BUFFERSA { DWORD // dwStructSize; struct _INTERNET_BUFFERSA *Next; LPCSTR lpcszHeader; DWORD dwHeadersLength; DWORD dwHeadersTotal; LPVOID lpvBuffer; // DWORD dwBufferLength; DWORD dwBufferTotal; DWORD dwOffsetLow; DWORD dwOffsetHigh; } INTERNET_BUFFERSA, *LPINTERNET_BUFFERSA; [PInvokeData("wininet.h", MSDNShortId = "9381184d-17f4-46ad-bd09-15c7e653d1b9")] [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] public struct INTERNET_BUFFERS { /// Size of the structure, in bytes. public uint dwStructSize; /// Pointer to the next INTERNET_BUFFERS structure. public IntPtr Next; /// Pointer to a string value that contains the headers. This member can be NULL. [MarshalAs(UnmanagedType.LPTStr)] public string lpcszHeader; /// Size of the headers, in TCHARs, if lpcszHeader is not NULL. public uint dwHeadersLength; /// Size of the headers, if there is not enough memory in the buffer. public uint dwHeadersTotal; /// Pointer to the data buffer. public IntPtr lpvBuffer; /// Size of the buffer, in bytes, if lpvBuffer is not NULL. public uint dwBufferLength; /// Total size of the resource, in bytes. public uint dwBufferTotal; /// Reserved; do not use. public uint dwOffsetLow; /// Reserved; do not use. public uint dwOffsetHigh; /// The default instance of INTERNET_BUFFERS with dwStructSize set. public static readonly INTERNET_BUFFERS Default = new INTERNET_BUFFERS { dwStructSize = (uint)Marshal.SizeOf(typeof(INTERNET_BUFFERS)) }; } /// Contains information about the configuration of the Internet cache. /// /// Note WinINet does not support server implementations. In addition, it should not be used from a service. For server /// implementations or services use Microsoft Windows HTTP Services (WinHTTP). /// // https://docs.microsoft.com/en-us/windows/win32/api/winineti/ns-winineti-internet_cache_config_infoa typedef struct // _INTERNET_CACHE_CONFIG_INFOA { DWORD dwStructSize; DWORD dwContainer; DWORD dwQuota; DWORD dwReserved4; BOOL fPerUser; DWORD // dwSyncMode; DWORD dwNumCachePaths; union { struct { CHAR CachePath[MAX_PATH]; DWORD dwCacheSize; }; // INTERNET_CACHE_CONFIG_PATH_ENTRYA CachePaths[ANYSIZE_ARRAY]; }; DWORD dwNormalUsage; DWORD dwExemptUsage; } // INTERNET_CACHE_CONFIG_INFOA, *LPINTERNET_CACHE_CONFIG_INFOA; [PInvokeData("winineti.h", MSDNShortId = "39019a94-6f14-4758-86f7-aba598e23d2e")] [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] public struct INTERNET_CACHE_CONFIG_INFO { /// Size of this structure, in bytes. This value can be used to help determine the version of the cache system. public uint dwStructSize; /// The container that the rest of the data in the struct applies to. 0 (zero) indicates the content container. public uint dwContainer; /// The cache quota limit of the container specified in kilobytes. public uint dwQuota; /// Reserved. public uint dwReserved4; /// Reserved. [MarshalAs(UnmanagedType.Bool)] public bool fPerUser; /// Reserved. public uint dwSyncMode; /// Reserved. public uint dwNumCachePaths; /// Reserved. [MarshalAs(UnmanagedType.ByValArray, SizeConst = 1)] public INTERNET_CACHE_CONFIG_PATH_ENTRY[] CachePaths; /// The cache size of the container specified in kilobytes. public uint dwNormalUsage; /// The number of kilobytes for this container exempt from scavenging. public uint dwExemptUsage; /// The default instance of INTERNET_CACHE_CONFIG_INFO with dwStructSize set. public static readonly INTERNET_CACHE_CONFIG_INFO Default = new INTERNET_CACHE_CONFIG_INFO { dwStructSize = (uint)Marshal.SizeOf(typeof(INTERNET_CACHE_CONFIG_INFO)) }; } /// Entry in INTERNET_CACHE_CONFIG_INFO. [PInvokeData("winineti.h", MSDNShortId = "39019a94-6f14-4758-86f7-aba598e23d2e")] [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] public struct INTERNET_CACHE_CONFIG_PATH_ENTRY { /// The cache path for the container in dwContainer. [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)] public string CachePath; /// The cache size in bytes. public uint dwCacheSize; } /// Contains information about an entry in the Internet cache. /// /// /// There is no cache entry size limit, so applications that need to enumerate the cache must be prepared to allocate variable-sized /// buffers. For more information, see Using Buffers. /// /// /// Note WinINet does not support server implementations. In addition, it should not be used from a service. For server /// implementations or services use Microsoft Windows HTTP Services (WinHTTP). /// /// // https://docs.microsoft.com/en-us/windows/win32/api/wininet/ns-wininet-internet_cache_entry_infoa typedef struct // _INTERNET_CACHE_ENTRY_INFOA { DWORD dwStructSize; LPSTR lpszSourceUrlName; LPSTR lpszLocalFileName; DWORD CacheEntryType; DWORD // dwUseCount; DWORD dwHitRate; DWORD dwSizeLow; DWORD dwSizeHigh; FILETIME LastModifiedTime; FILETIME ExpireTime; FILETIME // LastAccessTime; FILETIME LastSyncTime; LPSTR lpHeaderInfo; DWORD dwHeaderInfoSize; LPSTR lpszFileExtension; union { DWORD // dwReserved; DWORD dwExemptDelta; }; } INTERNET_CACHE_ENTRY_INFOA, *LPINTERNET_CACHE_ENTRY_INFOA; [PInvokeData("wininet.h", MSDNShortId = "7bda08e0-5df0-4087-a5cd-3a25c6ae5ade")] [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] public struct INTERNET_CACHE_ENTRY_INFO { /// Size of this structure, in bytes. This value can be used to help determine the version of the cache system. public uint dwStructSize; /// /// Pointer to a null-terminated string that contains the URL name. The string occupies the memory area at the end of this structure. /// public StrPtrAuto lpszSourceUrlName; /// /// Pointer to a null-terminated string that contains the local file name. The string occupies the memory area at the end of /// this structure. /// public StrPtrAuto lpszLocalFileName; /// /// /// A bitmask indicating the type of cache entry and its properties. The cache entry types include: history entries /// (URLHISTORY_CACHE_ENTRY), cookie entries (COOKIE_CACHE_ENTRY), and normal cached content (NORMAL_CACHE_ENTRY). /// /// This member can be zero or more of the following property flags, and cache type flags listed below. /// /// /// Value /// Meaning /// /// /// EDITED_CACHE_ENTRY /// Cache entry file that has been edited externally. This cache entry type is exempt from scavenging. /// /// /// SPARSE_CACHE_ENTRY /// Partial response cache entry. /// /// /// STICKY_CACHE_ENTRY /// /// Sticky cache entry that is exempt from scavenging for the amount of time specified by dwExemptDelta. The default value set /// by CommitUrlCacheEntryA and CommitUrlCacheEntryW is one day. /// /// /// /// TRACK_OFFLINE_CACHE_ENTRY /// Not currently implemented. /// /// /// TRACK_ONLINE_CACHE_ENTRY /// Not currently implemented. /// /// /// The following list contains the cache type flags. /// /// /// Value /// Meaning /// /// /// COOKIE_CACHE_ENTRY /// Cookie cache entry. /// /// /// NORMAL_CACHE_ENTRY /// Normal cache entry; can be deleted to recover space for new entries. /// /// /// URLHISTORY_CACHE_ENTRY /// Visited link cache entry. /// /// /// public CACHE_ENTRY_TYPE CacheEntryType; /// Current number of WinINEet callers using the cache entry. public uint dwUseCount; /// Number of times the cache entry was retrieved. public uint dwHitRate; /// Low-order portion of the file size, in bytes. public uint dwSizeLow; /// High-order portion of the file size, in bytes. public uint dwSizeHigh; /// FILETIME structure that contains the last modified time of this URL, in Greenwich mean time format. public FILETIME LastModifiedTime; /// FILETIME structure that contains the expiration time of this file, in Greenwich mean time format. public FILETIME ExpireTime; /// FILETIME structure that contains the last accessed time, in Greenwich mean time format. public FILETIME LastAccessTime; /// FILETIME structure that contains the last time the cache was synchronized. public FILETIME LastSyncTime; /// /// Pointer to a buffer that contains the header information. The buffer occupies the memory at the end of this structure. /// public StrPtrAuto lpHeaderInfo; /// Size of the lpHeaderInfo buffer, in TCHARs. public uint dwHeaderInfoSize; /// /// Pointer to a string that contains the file name extension used to retrieve the data as a file. The string occupies the /// memory area at the end of this structure. /// public StrPtrAuto lpszFileExtension; /// public uint dwReserved; /// Exemption time from the last accessed time, in seconds. public uint dwExemptDelta; /// The default instance of INTERNET_CACHE_ENTRY_INFO with dwStructSize set. public static readonly INTERNET_CACHE_ENTRY_INFO Default = new INTERNET_CACHE_ENTRY_INFO { dwStructSize = (uint)Marshal.SizeOf(typeof(INTERNET_CACHE_ENTRY_INFO)) }; } /// Contains information about an entry in the Internet cache. /// /// /// There is no cache entry size limit, so applications that need to enumerate the cache must be prepared to allocate variable-sized /// buffers. For more information, see Using Buffers. /// /// /// Note WinINet does not support server implementations. In addition, it should not be used from a service. For server /// implementations or services use Microsoft Windows HTTP Services (WinHTTP). /// /// // https://docs.microsoft.com/en-us/windows/win32/api/wininet/ns-wininet-internet_cache_entry_infoa typedef struct // _INTERNET_CACHE_ENTRY_INFOA { DWORD dwStructSize; LPSTR lpszSourceUrlName; LPSTR lpszLocalFileName; DWORD CacheEntryType; DWORD // dwUseCount; DWORD dwHitRate; DWORD dwSizeLow; DWORD dwSizeHigh; FILETIME LastModifiedTime; FILETIME ExpireTime; FILETIME // LastAccessTime; FILETIME LastSyncTime; LPSTR lpHeaderInfo; DWORD dwHeaderInfoSize; LPSTR lpszFileExtension; union { DWORD // dwReserved; DWORD dwExemptDelta; }; } INTERNET_CACHE_ENTRY_INFOA, *LPINTERNET_CACHE_ENTRY_INFOA; [PInvokeData("wininet.h", MSDNShortId = "7bda08e0-5df0-4087-a5cd-3a25c6ae5ade")] public struct INTERNET_CACHE_ENTRY_INFO_MGD { /// A bitmask indicating the type of cache entry and its properties. public CACHE_ENTRY_TYPE CacheEntryType; /// Exemption time from the last accessed time, in seconds. public TimeSpan dwExemptDelta; /// Number of times the cache entry was retrieved. public uint dwHitRate; /// The file size, in bytes. public ulong dwSize; /// Current number of WinINEet callers using the cache entry. public uint dwUseCount; /// FILETIME structure that contains the expiration time of this file, in Greenwich mean time format. public DateTime ExpireTime; /// FILETIME structure that contains the last accessed time, in Greenwich mean time format. public DateTime LastAccessTime; /// FILETIME structure that contains the last modified time of this URL, in Greenwich mean time format. public DateTime LastModifiedTime; /// FILETIME structure that contains the last time the cache was synchronized. public DateTime LastSyncTime; /// /// Pointer to a buffer that contains the header information. The buffer occupies the memory at the end of this structure. /// public string lpHeaderInfo; /// /// Pointer to a string that contains the file name extension used to retrieve the data as a file. The string occupies the /// memory area at the end of this structure. /// public string lpszFileExtension; /// /// Pointer to a null-terminated string that contains the local file name. The string occupies the memory area at the end of /// this structure. /// public string lpszLocalFileName; /// /// Pointer to a null-terminated string that contains the URL name. The string occupies the memory area at the end of this structure. /// public string lpszSourceUrlName; /// Initializes a new instance of the struct from an unmanaged structure. /// The instance. public INTERNET_CACHE_ENTRY_INFO_MGD(in INTERNET_CACHE_ENTRY_INFO i) { lpszSourceUrlName = i.lpszSourceUrlName; lpszLocalFileName = i.lpszLocalFileName; lpHeaderInfo = i.lpHeaderInfo; lpszFileExtension = i.lpszFileExtension; CacheEntryType = i.CacheEntryType; dwUseCount = i.dwUseCount; dwHitRate = i.dwHitRate; dwSize = Macros.MAKELONG64(i.dwSizeLow, i.dwSizeHigh); LastModifiedTime = i.LastModifiedTime.ToDateTime(); ExpireTime = i.ExpireTime.ToDateTime(); LastAccessTime = i.LastAccessTime.ToDateTime(); LastSyncTime = i.LastSyncTime.ToDateTime(); dwExemptDelta = TimeSpan.FromSeconds(i.dwExemptDelta); } } /// Contains the LastModified and Expire times for a resource stored in the Internet cache. [PInvokeData("WinInet.h")] [StructLayout(LayoutKind.Sequential)] public struct INTERNET_CACHE_TIMESTAMPS { /// FILETIME structure that contains the Expires time. public FILETIME ftExpires; /// FILETIME structure that contains the LastModified time. public FILETIME ftLastModified; } /// Contains certificate information returned from the server. This structure is used by the InternetQueryOption function. /// /// Despite what the header indicates, the implementation of INTERNET_CERTIFICATE_INFO is not Unicode-aware. All of the string /// members are filled as ANSI strings regardless of whether Unicode is enabled. Consequently, when reading these values, the caller /// must cast them to LPSTR if Unicode is enabled. /// [PInvokeData("WinInet.h")] [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] public struct INTERNET_CERTIFICATE_INFO { /// FILETIME structure that contains the date the certificate expires. public FILETIME ftExpiry; /// FILETIME structure that contains the date the certificate becomes valid. public FILETIME ftStart; /// /// Pointer to a buffer that contains the name of the organization, site, and server for which the certificate was issued. The /// application must call LocalFree to release the resources allocated for this parameter. /// public StrPtrAnsi lpszSubjectInfo; /// /// Pointer to a buffer that contains the name of the organization, site, and server that issued the certificate. The /// application must call LocalFree to release the resources allocated for this parameter. /// public StrPtrAnsi lpszIssuerInfo; /// /// Pointer to a buffer that contains the name of the protocol used to provide the secure connection. The application must call /// LocalFree to release the resources allocated for this parameter. /// public StrPtrAnsi lpszProtocolName; /// /// Pointer to a buffer that contains the name of the algorithm used for signing the certificate. The application must call /// LocalFree to release the resources allocated for this parameter. /// public StrPtrAnsi lpszSignatureAlgName; /// /// Pointer to a buffer that contains the name of the algorithm used for doing encryption over the secure channel (SSL/PCT) /// connection. The application must call LocalFree to release the resources allocated for this parameter. /// public StrPtrAnsi lpszEncryptionAlgName; /// Size, in TCHARs, of the key. public uint dwKeySize; } /// /// The INTERNET_DIAGNOSTIC_SOCKET_INFO structure is returned by the InternetQueryOption function when the /// INTERNET_OPTION_DIAGNOSTIC_SOCKET_INFO flag is passed to it together with a handle to an HTTP Request. The /// INTERNET_DIAGNOSTIC_SOCKET_INFO structure contains information about the socket associated with that HTTP Request. /// [PInvokeData("WinInet.h")] [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] public struct INTERNET_DIAGNOSTIC_SOCKET_INFO { /// Descriptor that identifies the socket associated with the specified HTTP Request. public IntPtr Socket; /// The address of the port at which the HTTP Request and response was received. public uint SourcePort; /// The address of the port at which the response was sent. public uint DestPort; /// The flags public IDSI_Flags Flags; } /// Contains the value of an option. /// /// /// In Internet Explorer 5, only the ANSI versions of InternetQueryOption and InternetSetOption will work with the /// INTERNET_PER_CONN_OPTION structure. The Unicode versions will support the INTERNET_PER_CONN_OPTION structure in /// later versions of Internet Explorer. /// /// /// For queries that return strings, InternetQueryOption allocates the memory for the pszValue member of the structure. The /// calling application must free this memory using the GlobalFree function when it has finished using the string. /// /// /// Note WinINet does not support server implementations. In addition, it should not be used from a service. For server /// implementations or services use Microsoft Windows HTTP Services (WinHTTP). /// /// // https://docs.microsoft.com/en-us/windows/win32/api/wininet/ns-wininet-internet_per_conn_optiona typedef struct { DWORD dwOption; // union { DWORD dwValue; LPSTR pszValue; FILETIME ftValue; } Value; } INTERNET_PER_CONN_OPTIONA, *LPINTERNET_PER_CONN_OPTIONA; [PInvokeData("wininet.h", MSDNShortId = "NS:wininet.__unnamed_struct_3")] [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] public struct INTERNET_PER_CONN_OPTION { /// /// Option to be queried or set. This member can be one of the following values. /// /// /// Value /// Meaning /// /// /// INTERNET_PER_CONN_AUTOCONFIG_URL /// Sets or retrieves a string containing the URL to the automatic configuration script. /// /// /// INTERNET_PER_CONN_AUTODISCOVERY_FLAGS /// /// Sets or retrieves the automatic discovery settings. The Value member will contain one or more of the following values: /// AUTO_PROXY_FLAG_ALWAYS_DETECT Always automatically detect settings. AUTO_PROXY_FLAG_CACHE_INIT_RUN Indicates that the cached /// results of the automatic proxy configuration script should be used, instead of actually running the script, unless the /// cached file has expired. AUTO_PROXY_FLAG_DETECTION_RUN Automatic detection has been run at least once on this connection. /// AUTO_PROXY_FLAG_DETECTION_SUSPECT Not currently supported. AUTO_PROXY_FLAG_DONT_CACHE_PROXY_RESULT Do not allow the caching /// of the result of the automatic proxy configuration script. AUTO_PROXY_FLAG_MIGRATED The setting was migrated from a /// Microsoft Internet Explorer 4.0 installation, and automatic detection should be attempted once. AUTO_PROXY_FLAG_USER_SET The /// user has explicitly set the automatic detection. /// /// /// /// INTERNET_PER_CONN_FLAGS /// /// Sets or retrieves the connection type. The Value member will contain one or more of the following values: PROXY_TYPE_DIRECT /// The connection does not use a proxy server. PROXY_TYPE_PROXY The connection uses an explicitly set proxy server. /// PROXY_TYPE_AUTO_PROXY_URL The connection downloads and processes an automatic configuration script at a specified URL. /// PROXY_TYPE_AUTO_DETECT The connection automatically detects settings. /// /// /// /// INTERNET_PER_CONN_PROXY_BYPASS /// Sets or retrieves a string containing the URLs that do not use the proxy server. /// /// /// INTERNET_PER_CONN_PROXY_SERVER /// Sets or retrieves a string containing the proxy servers. /// /// /// INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL /// /// Chained autoconfig URL. Used when the primary autoconfig URL points to an INS file that sets a second autoconfig URL for /// proxy information. /// /// /// /// INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS /// of minutes until automatic refresh of autoconfig URL by autodiscovery. /// /// /// INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME /// Read only option. Returns the time the last known good autoconfig URL was found using autodiscovery. /// /// /// INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL /// Read only option. Returns the last known good URL found using autodiscovery. /// /// /// Windows 7 and later: /// /// Clients that support Internet Explorer 8 should query the connection type using INTERNET_PER_CONN_FLAGS_UI. If this /// query fails, then the system is running a previous version of Internet Explorer and the client should query again with INTERNET_PER_CONN_FLAGS. /// /// Restore the connection type using /// INTERNET_PER_CONN_FLAGS /// regardless of the version of Internet Explorer. /// /// /// Value /// Meaning /// /// /// INTERNET_PER_CONN_FLAGS_UI /// /// Sets or retrieves the connection type. The Value member will contain one or more of the following values: PROXY_TYPE_DIRECT /// The connection does not use a proxy server. PROXY_TYPE_PROXY The connection uses an explicitly set proxy server. /// PROXY_TYPE_AUTO_PROXY_URL The connection downloads and processes an automatic configuration script at a specified URL. /// PROXY_TYPE_AUTO_DETECT The connection automatically detects settings. /// /// /// /// public INTERNET_PER_CONN_OPTION_ID dwOption; /// /// Union that contains the value for the option. It can be any one of the following types depending on the value of dwOption: /// dwValue /// Unsigned long integer value. /// pszValue /// Pointer to a string value. /// ftValue /// A FILETIME structure. /// public INTERNET_PER_CONN_OPTION_Value Value; /// /// Union that contains the value for the option. It can be any one of the following types depending on the value of dwOption. /// [StructLayout(LayoutKind.Explicit)] public struct INTERNET_PER_CONN_OPTION_Value { /// Unsigned long integer value. [FieldOffset(0)] public uint dwValue; /// Pointer to a string value. [FieldOffset(0)] public StrPtrAuto pszValue; /// A FILETIME structure. [FieldOffset(0)] public FILETIME ftValue; } } /// Contains the list of options for a particular Internet connection. [PInvokeData("WinInet.h")] [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] public struct INTERNET_PER_CONN_OPTION_LIST { /// Size of the structure, in bytes. public uint dwSize; /// /// Pointer to a string that contains the name of the RAS connection or NULL, which indicates the default or LAN connection, to /// set or query options on. /// public StrPtrAuto pszConnection; /// Number of options to query or set. public uint dwOptionCount; /// Options that failed, if an error occurs. public uint dwOptionError; /// Pointer to an array of INTERNET_PER_CONN_OPTION structures containing the options to query or set. public IntPtr pOptions; /// The default instance of INTERNET_PER_CONN_OPTION_LIST with dwSize set. public static readonly INTERNET_PER_CONN_OPTION_LIST Default = new INTERNET_PER_CONN_OPTION_LIST { dwSize = (uint)Marshal.SizeOf(typeof(INTERNET_PER_CONN_OPTION_LIST)) }; } /// /// Contains information that is supplied with the INTERNET_OPTION_PROXY value to get or set proxy information on a handle obtained /// from a call to the InternetOpen function. /// [PInvokeData("WinInet.h")] [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] public struct INTERNET_PROXY_INFO { /// Access type. public InternetOpenType dwAccessType; /// Pointer to a string that contains the proxy server list. public StrPtrAuto lpszProxy; /// Pointer to a string that contains the proxy bypass list. public StrPtrAuto lpszProxyBypass; } /// /// Contains the HTTP version number of the server. This structure is used when passing the INTERNET_OPTION_VERSION flag to the /// InternetQueryOption function. /// [PInvokeData("WinInet.h")] [StructLayout(LayoutKind.Sequential)] public struct INTERNET_VERSION_INFO { /// Major version number. public uint dwMajorVersion; /// Minor version number. public uint dwMinorVersion; } /// /// Contains the constituent parts of a URL. This structure is used with the InternetCrackUrl and InternetCreateUrl functions. /// /// /// /// For InternetCrackUrl, if a pointer member and its corresponding length member are both zero, that component is not returned. If /// the pointer member is NULL but the length member is not zero, both the pointer and length members are returned. If both /// pointer and corresponding length members are nonzero, the pointer member points to a buffer where the component is copied. The /// component can be un-escaped, depending on the dwFlags parameter of InternetCrackUrl. /// /// /// For InternetCreateUrl, the pointer members should be NULL if the component is not required. If the corresponding length /// member is zero, the pointer member is the address of a zero-terminated string. If the length member is not zero, it is the /// string length of the corresponding pointer member. /// /// /// Note WinINet does not support server implementations. In addition, it should not be used from a service. For server /// implementations or services use Microsoft Windows HTTP Services (WinHTTP). /// /// // https://docs.microsoft.com/en-us/windows/win32/api/wininet/ns-wininet-url_componentsa typedef struct { DWORD dwStructSize; LPSTR // lpszScheme; DWORD dwSchemeLength; INTERNET_SCHEME nScheme; LPSTR lpszHostName; DWORD dwHostNameLength; INTERNET_PORT nPort; LPSTR // lpszUserName; DWORD dwUserNameLength; LPSTR lpszPassword; DWORD dwPasswordLength; LPSTR lpszUrlPath; DWORD dwUrlPathLength; LPSTR // lpszExtraInfo; DWORD dwExtraInfoLength; } URL_COMPONENTSA, *LPURL_COMPONENTSA; [PInvokeData("wininet.h", MSDNShortId = "faebdd29-f746-486b-b779-cceeecac9163")] [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] public struct URL_COMPONENTS { /// Size of this structure, in bytes. public uint dwStructSize; /// Pointer to a string that contains the scheme name. public IntPtr lpszScheme; /// Size of the scheme name, in TCHARs. public uint dwSchemeLength; /// INTERNET_SCHEME value that indicates the Internet protocol scheme. public INTERNET_SCHEME nScheme; /// Pointer to a string that contains the host name. public IntPtr lpszHostName; /// Size of the host name, in TCHARs. public uint dwHostNameLength; /// Converted port number. public INTERNET_PORT nPort; /// Pointer to a string value that contains the user name. public IntPtr lpszUserName; /// Size of the user name, in TCHARs. public uint dwUserNameLength; /// Pointer to a string that contains the password. public IntPtr lpszPassword; /// Size of the password, in TCHARs. public uint dwPasswordLength; /// Pointer to a string that contains the URL path. public IntPtr lpszUrlPath; /// Size of the URL path, in TCHARs. public uint dwUrlPathLength; /// Pointer to a string that contains the extra information (for example, ?something or #something). public IntPtr lpszExtraInfo; /// Size of the extra information, in TCHARs. public uint dwExtraInfoLength; /// The default instance of URL_COMPONENTS with dwStructSize set. public static readonly URL_COMPONENTS Default = new URL_COMPONENTS { dwStructSize = (uint)Marshal.SizeOf(typeof(URL_COMPONENTS)) }; } /// Provides a for that is disposed using . public class SafeHCACHEENTRYSTREAM : SafeHANDLE { /// Initializes a new instance of the class and assigns an existing handle. /// An object that represents the pre-existing handle to use. /// /// to reliably release the handle during the finalization phase; otherwise, (not recommended). /// public SafeHCACHEENTRYSTREAM(IntPtr preexistingHandle, bool ownsHandle = true) : base(preexistingHandle, ownsHandle) { } /// Initializes a new instance of the class. private SafeHCACHEENTRYSTREAM() : base() { } /// Performs an implicit conversion from to . /// The safe handle instance. /// The result of the conversion. public static implicit operator HCACHEENTRYSTREAM(SafeHCACHEENTRYSTREAM h) => h.handle; /// protected override bool InternalReleaseHandle() => UnlockUrlCacheEntryStream(handle); } /// Provides a for that is disposed using . public class SafeHINTERNET : SafeHANDLE { /// Initializes a new instance of the class and assigns an existing handle. /// An object that represents the pre-existing handle to use. /// /// to reliably release the handle during the finalization phase; otherwise, (not recommended). /// public SafeHINTERNET(IntPtr preexistingHandle, bool ownsHandle = true) : base(preexistingHandle, ownsHandle) { } /// Initializes a new instance of the class. internal SafeHINTERNET() : base() { } /// Represents a NULL value for this handle. public static SafeHINTERNET Null => new SafeHINTERNET(); /// Performs an implicit conversion from to . /// The safe handle instance. /// The result of the conversion. public static implicit operator HINTERNET(SafeHINTERNET h) => h.handle; /// protected override bool InternalReleaseHandle() => InternetCloseHandle(handle); } /// A managed equivalent to . /// public class URL_COMPONENTS_MGD : IDisposable { private readonly SafeCoTaskMemString scheme, host, user, pwd, url, extra; private URL_COMPONENTS uc; /// Initializes a new instance of the class. public URL_COMPONENTS_MGD() { uc.dwStructSize = (uint)Marshal.SizeOf(typeof(URL_COMPONENTS)); uc.lpszScheme = scheme = new SafeCoTaskMemString((int)(uc.dwSchemeLength = INTERNET_MAX_SCHEME_LENGTH + 1), CharSet.Auto); uc.lpszHostName = host = new SafeCoTaskMemString((int)(uc.dwHostNameLength = INTERNET_MAX_HOST_NAME_LENGTH + 1), CharSet.Auto); uc.lpszUserName = user = new SafeCoTaskMemString((int)(uc.dwUserNameLength = INTERNET_MAX_USER_NAME_LENGTH + 1), CharSet.Auto); uc.lpszPassword = pwd = new SafeCoTaskMemString((int)(uc.dwPasswordLength = INTERNET_MAX_PASSWORD_LENGTH + 1), CharSet.Auto); uc.lpszUrlPath = url = new SafeCoTaskMemString((int)(uc.dwUrlPathLength = INTERNET_MAX_PATH_LENGTH + 1), CharSet.Auto); uc.lpszExtraInfo = extra = new SafeCoTaskMemString((int)(uc.dwExtraInfoLength = INTERNET_MAX_PATH_LENGTH + 1), CharSet.Auto); } /// Initializes a new instance of the class with values. /// The scheme. /// The host. /// The URL path. /// The extra information. /// The port. /// Name of the user. /// The password. public URL_COMPONENTS_MGD(string scheme, string host, string path = null, string extra = null, INTERNET_PORT port = INTERNET_PORT.INTERNET_INVALID_PORT_NUMBER, string userName = null, string password = null) : this() { lpszScheme = scheme ?? ""; lpszHostName = host ?? ""; lpszUrlPath = path ?? ""; lpszExtraInfo = extra ?? ""; nPort = port; lpszUserName = userName ?? ""; lpszPassword = password ?? ""; } /// Pointer to a string that contains the extra information (for example, ?something or #something). public string lpszExtraInfo { get => extra; set { extra.Set(value); uc.dwExtraInfoLength = (uint)(value?.Length ?? 0); } } /// Pointer to a string that contains the host name. public string lpszHostName { get => host; set { host.Set(value); uc.dwHostNameLength = (uint)(value?.Length ?? 0); } } /// Pointer to a string that contains the password. public string lpszPassword { get => pwd; set { pwd.Set(value); uc.dwPasswordLength = (uint)(value?.Length ?? 0); } } /// Pointer to a string that contains the scheme name. public string lpszScheme { get => scheme; set { scheme.Set(value); uc.dwSchemeLength = (uint)(value?.Length ?? 0); } } /// Pointer to a string that contains the URL path. public string lpszUrlPath { get => url; set { url.Set(value); uc.dwUrlPathLength = (uint)(value?.Length ?? 0); } } /// Pointer to a string value that contains the user name. public string lpszUserName { get => user; set { user.Set(value); uc.dwUserNameLength = (uint)(value?.Length ?? 0); } } /// Converted port number. public INTERNET_PORT nPort { get => uc.nPort; set => uc.nPort = value; } /// INTERNET_SCHEME value that indicates the Internet protocol scheme. public INTERNET_SCHEME nScheme { get => uc.nScheme; set => uc.nScheme = value; } /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. public void Dispose() { scheme.Dispose(); host.Dispose(); user.Dispose(); pwd.Dispose(); url.Dispose(); extra.Dispose(); } /// Gets a reference to the unmanaged structure. /// A reference to . public ref URL_COMPONENTS GetRef() => ref uc; } } }