CONST INTERNET_DEFAULT_PORT = 0
CONST INTERNET_DEFAULT_HTTP_PORT = 80
CONST INTERNET_DEFAULT_HTTPS_PORT = 443

CONST WINHTTP_ACCESS_TYPE_DEFAULT_PROXY = 0
CONST WINHTTP_ACCESS_TYPE_NO_PROXY = 1
CONST WINHTTP_ACCESS_TYPE_NAMED_PROXY = 3

CONST WINHTTP_NO_PROXY_NAME = 0
CONST WINHTTP_NO_PROXY_BYPASS = 0
CONST WINHTTP_NO_REFERER = 0
CONST WINHTTP_NO_ADDITIONAL_HEADERS = 0
CONST WINHTTP_NO_REQUEST_DATA = 0

CONST WINHTTP_DEFAULT_ACCEPT_TYPES = 0

CONST WINHTTP_FLAG_REFRESH = &H100
CONST WINHTTP_FLAG_SECURE = &H00800000

CONST WINHTTP_OPTION_SECURITY_FLAGS = 31

CONST SECURITY_FLAG_IGNORE_UNKNOWN_CA = &H100
CONST SECURITY_FLAG_IGNORE_CERT_WRONG_USAGE = &H200
CONST SECURITY_FLAG_IGNORE_CERT_CN_INVALID = &H1000
CONST SECURITY_FLAG_IGNORE_CERT_DATE_INVALID = &H2000

ENUM
  WINHTTP_ERROR_BASE = 12000
  ERROR_WINHTTP_OUT_OF_HANDLES = WINHTTP_ERROR_BASE + 1
  ERROR_WINHTTP_TIMEOUT = WINHTTP_ERROR_BASE + 2
  ERROR_WINHTTP_INTERNAL_ERROR = WINHTTP_ERROR_BASE + 4
  ERROR_WINHTTP_INVALID_URL = WINHTTP_ERROR_BASE + 5
  ERROR_WINHTTP_UNRECOGNIZED_SCHEME = WINHTTP_ERROR_BASE + 6
  ERROR_WINHTTP_NAME_NOT_RESOLVED = WINHTTP_ERROR_BASE + 7
  ERROR_WINHTTP_INVALID_OPTION = WINHTTP_ERROR_BASE + 9
  ERROR_WINHTTP_OPTION_NOT_SETTABLE = WINHTTP_ERROR_BASE + 11
  ERROR_WINHTTP_SHUTDOWN = WINHTTP_ERROR_BASE + 12
  ERROR_WINHTTP_LOGIN_FAILURE = WINHTTP_ERROR_BASE + 15
  ERROR_WINHTTP_OPERATION_CANCELLED = WINHTTP_ERROR_BASE + 17
  ERROR_WINHTTP_INCORRECT_HANDLE_TYPE = WINHTTP_ERROR_BASE + 18
  ERROR_WINHTTP_INCORRECT_HANDLE_STATE = WINHTTP_ERROR_BASE + 19
  ERROR_WINHTTP_CANNOT_CONNECT = WINHTTP_ERROR_BASE + 29
  ERROR_WINHTTP_CONNECTION_ERROR = WINHTTP_ERROR_BASE + 30
  ERROR_WINHTTP_RESEND_REQUEST = WINHTTP_ERROR_BASE + 32
  ERROR_WINHTTP_SECURE_CERT_DATE_INVALID = WINHTTP_ERROR_BASE + 37
  ERROR_WINHTTP_SECURE_CERT_CN_INVALID = WINHTTP_ERROR_BASE + 38
  ERROR_WINHTTP_CLIENT_AUTH_CERT_NEEDED = WINHTTP_ERROR_BASE + 44
  ERROR_WINHTTP_SECURE_INVALID_CA = WINHTTP_ERROR_BASE + 45
  ERROR_WINHTTP_SECURE_CERT_REV_FAILED = WINHTTP_ERROR_BASE + 57
  ERROR_WINHTTP_CANNOT_CALL_BEFORE_OPEN = WINHTTP_ERROR_BASE + 100
  ERROR_WINHTTP_CANNOT_CALL_BEFORE_SEND = WINHTTP_ERROR_BASE + 101
  ERROR_WINHTTP_CANNOT_CALL_AFTER_SEND = WINHTTP_ERROR_BASE + 102
  ERROR_WINHTTP_CANNOT_CALL_AFTER_OPEN = WINHTTP_ERROR_BASE + 103
  ERROR_WINHTTP_HEADER_NOT_FOUND = WINHTTP_ERROR_BASE + 150
  ERROR_WINHTTP_INVALID_SERVER_RESPONSE = WINHTTP_ERROR_BASE + 152
  ERROR_WINHTTP_INVALID_HEADER = WINHTTP_ERROR_BASE + 153
  ERROR_WINHTTP_INVALID_QUERY_REQUEST = WINHTTP_ERROR_BASE + 154
  ERROR_WINHTTP_HEADER_ALREADY_EXISTS = WINHTTP_ERROR_BASE + 155
  ERROR_WINHTTP_REDIRECT_FAILED = WINHTTP_ERROR_BASE + 156
  ERROR_WINHTTP_SECURE_CHANNEL_ERROR = WINHTTP_ERROR_BASE + 157
  ERROR_WINHTTP_BAD_AUTO_PROXY_SCRIPT = WINHTTP_ERROR_BASE + 166
  ERROR_WINHTTP_UNABLE_TO_DOWNLOAD_SCRIPT = WINHTTP_ERROR_BASE + 167
  ERROR_WINHTTP_SECURE_INVALID_CERT = WINHTTP_ERROR_BASE + 169
  ERROR_WINHTTP_SECURE_CERT_REVOKED = WINHTTP_ERROR_BASE + 170
  ERROR_WINHTTP_NOT_INITIALIZED = WINHTTP_ERROR_BASE + 172
  ERROR_WINHTTP_SECURE_FAILURE = WINHTTP_ERROR_BASE + 175
  ERROR_WINHTTP_AUTO_PROXY_SERVICE_ERROR = WINHTTP_ERROR_BASE + 178
  ERROR_WINHTTP_SECURE_CERT_WRONG_USAGE = WINHTTP_ERROR_BASE + 179
  ERROR_WINHTTP_AUTODETECTION_FAILED = WINHTTP_ERROR_BASE + 180
  ERROR_WINHTTP_HEADER_COUNT_EXCEEDED = WINHTTP_ERROR_BASE + 181
  ERROR_WINHTTP_HEADER_SIZE_OVERFLOW = WINHTTP_ERROR_BASE + 182
  ERROR_WINHTTP_CHUNKED_ENCODING_HEADER_SIZE_OVERFLOW = WINHTTP_ERROR_BASE + 183
  ERROR_WINHTTP_RESPONSE_DRAIN_OVERFLOW = WINHTTP_ERROR_BASE + 184
  ERROR_WINHTTP_CLIENT_CERT_NO_PRIVATE_KEY = WINHTTP_ERROR_BASE + 185
  ERROR_WINHTTP_CLIENT_CERT_NO_ACCESS_PRIVATE_KEY = WINHTTP_ERROR_BASE + 186
END ENUM

EXTERN "Windows"
  DECLARE FUNCTION WinHttpAddRequestHeaders( _
    hRequest AS ULONG PTR, _
    lpszHeaders AS CONST WSTRING PTR, _
    dwHeadersLength AS LONG, _
    dwModifiers AS LONG _
  ) AS LONG
  
  DECLARE FUNCTION WinHttpCloseHandle( _
    hInternet AS ULONG PTR _
  ) AS LONG
  
  DECLARE FUNCTION WinHttpConnect( _
    hSession AS ULONG PTR, _
    pswzServerName AS CONST WSTRING PTR, _
    nServerPort AS LONG, _
    dwReserved AS LONG = 0 _
  ) AS ULONG PTR
  
  DECLARE FUNCTION WinHttpOpen( _
    pszAgentW AS CONST WSTRING PTR, _
    dwAccessType AS LONG, _
    pszProxyW AS CONST WSTRING PTR, _
    pszProxyBypassW AS CONST WSTRING PTR, _
    dwFlags AS ULONG = 0 _
  ) AS ULONG PTR
  
  DECLARE FUNCTION WinHttpOpenRequest( _
    hConnect AS ULONG PTR, _
    pwszVerb AS CONST WSTRING PTR, _
    pwszObjectName AS CONST WSTRING PTR, _
    pwszVersion AS CONST WSTRING PTR, _
    pwszReferrer AS CONST WSTRING PTR, _
    ppwszAcceptTypes AS CONST WSTRING PTR PTR, _
    dwFlags AS ULONG _
  ) AS ULONG PTR
  
  DECLARE FUNCTION WinHttpQueryDataAvailable( _
    hRequest AS ULONG PTR, _
    lpdwNumberOfBytesAvailable AS ULONG PTR _
  ) AS LONG
  
  DECLARE FUNCTION WinHttpReadData( _
    hRequest AS ULONG PTR, _
    lpBuffer AS ULONG PTR, _
    dwNumberOfBytesToRead AS ULONG, _
    lpdwNumberOfBytesRead AS ULONG PTR _
  ) AS LONG
  
  DECLARE FUNCTION WinHttpReceiveResponse( _
    hRequest AS ULONG PTR, _
    lpReserved AS LONG = 0 _
  ) AS LONG
  
  DECLARE FUNCTION WinHttpSendRequest( _
    hRequest AS ULONG PTR, _
    lpszHeaders AS CONST WSTRING PTR, _
    dwHeadersLength AS ULONG, _
    lpOptional AS ULONG PTR, _
    dwOptionalLength AS ULONG, _
    dwTotalLength AS ULONG, _
    dwContext AS ULONG PTR _
  ) AS LONG
  
  DECLARE FUNCTION WinHttpSetOption( _
    hInternet AS ULONG PTR, _
    dwOption AS ULONG, _
    lpBuffer AS ULONG PTR, _
    dwBufferLength AS ULONG _
  ) AS LONG
  
  DECLARE FUNCTION GetLastError() AS LONG
END EXTERN
