Share via


CInternetSession::OpenURL

Call this member function to send the specified request to the HTTP server and allow the client to specify additional RFC822, MIME, or HTTP headers to send along with the request.

CStdioFile* OpenURL( 
   LPCTSTR pstrURL, 
   DWORD_PTR dwContext = 1, 
   DWORD dwFlags = INTERNET_FLAG_TRANSFER_ASCII, 
   LPCTSTR pstrHeaders = NULL, 
   DWORD dwHeadersLength = 0  
);

Parameters

  • pstrURL
    A pointer to the name of the URL to begin reading. Only URLs beginning with file:, ftp:, gopher:, or http: are supported. ASSERTS if pszURL is NULL.

  • dwContext
    An application-defined value passed with the returned handle in callback.

  • dwFlags
    The flags describing how to handle this connection. See Remarks for more information about the valid flags. The valid flags are:

    • INTERNET_FLAG_TRANSFER_ASCII   The default. Transfer the file as ASCII text.

    • INTERNET_FLAG_TRANSFER_BINARY   Transfer the file as a binary file.

    • INTERNET_FLAG_RELOAD   Get the data from the wire even if it is locally cached.

    • INTERNET_FLAG_DONT_CACHE   Do not cache the data, either locally or in any gateways.

    • INTERNET_FLAG_SECURE   This flag is applicable to HTTP requests only. It requests secure transactions on the wire with Secure Sockets Layer or PCT.

    • INTERNET_OPEN_FLAG_USE_EXISTING_CONNECT   If possible, reuse the existing connections to the server for new requests generated by OpenUrl instead of creating a new session for each connection request.

    • INTERNET_FLAG_PASSIVE   Used for an FTP site. Uses passive FTP semantics. Used with CInternetConnection of OpenURL.

  • pstrHeaders
    A pointer to a string containing the headers to be sent to the HTTP server.

  • dwHeadersLength
    The length, in characters, of the additional headers. If this is -1L and pstrHeaders is non-NULL, then pstrHeaders is assumed to be zero terminated and the length is calculated.

Return Value

Returns a file handle for FTP, GOPHER, HTTP, and FILE-type Internet services only. Returns NULL if parsing was unsuccessful.

The pointer that OpenURL returns depends on pszURL's type of service. The table below illustrates the possible pointers OpenURL can return.

URL type

Returns

file://

CStdioFile*

http://

CHttpFile*

gopher://

CGopherFile*

ftp://

CInternetFile*

Remarks

The parameter dwFlags must include either INTERNET_FLAG_TRANSFER_ASCII or INTERNET_FLAG_TRANSFER_BINARY, but not both. The remaining flags can be combined with the bitwise OR operator (|).

OpenURL, which wraps the Win32 function InternetOpenURL, allows only downloading, retrieving, and reading the data from an Internet server. OpenURL allows no file manipulation on a remote location, so it requires no CInternetConnection object.

To use connection-specific (that is, protocol-specific) functions, such as writing to a file, you must open a session, then open a particular kind of connection, then use that connection to open a file in the desired mode. See CInternetConnection for more information about connection-specific functions.

Exceptions

This method can throw exceptions of type CInternetException*.

Requirements

Header: afxinet.h

See Also

Reference

CInternetSession Class

Hierarchy Chart

CInternetConnection Class

CGopherConnection Class

CInternetSession::GetFtpConnection

CInternetSession::GetHttpConnection