Using a Proxy Server

< BACK  NEXT >
[oR]

Many organizations install proxy servers to filter IP packets to control access to internal systems from other users on the Internet, and perhaps to control the type of protocols or servers that users in the organization can access. In this situation users actually communicate with the proxy server, and the proxy server connects to the requested server on the user's behalf. Thus, when writing code, you need to instruct the Internet functions to use the proxy server. This is done when calling InternetOpen. For example, the following code fragment specifies that a proxy server with the name "SPPROXY" should be used.

 hHttpOpen = InternetOpen(_T("Example Agent"),     INTERNET_OPEN_TYPE_PROXY,     _T("SPPROXY"), // proxy server     NULL,   // no bypass addresses     0);     // no flags 

The proxy is specified by passing (see Table 8.1):

  1. INTERNET_OPEN_TYPE_PROXY in the dwAccessType parameter specifying the use of a proxy server.

  2. The proxy name (for example, "SPPROXY") in the lpszProxy parameter. This could be an IP address, such as "192.168.0.2".

Note that bypass addresses are not supported in Windows CE. In Windows NT/98/2000, bypass addresses can be used to specify servers that should be accessed directly and not through the proxy server.

In Windows CE proxy server information can be stored in the registry, and InternetOpen can read the registry keys directly. This is done by specifying the INTERNET_OPEN_TYPE_PRECONFIG dwAccessType constant:

 hHttpOpen = InternetOpen(_T("Example Agent"),   INTERNET_OPEN_TYPE_PRECONFIG,   NULL, // default proxy   NULL, // no bypass addresses   0);   // no flags 

The registry key HKEY_CURRENT_USER\Comm\Wininet\ProxyServer stores the proxy information. The value specifies the name of the server and port number in the form "protocol=scheme://server:port". Windows CE only supports accessing servers through a single proxy server. For example, the proxy server "spproxy" would be specified by:

 Key:     HKEY_CURRENT_USER\Comm\Wininet\ProxyServer Value:   HTTP=http://spproxy:80 

If INTERNET_OPEN_TYPE_PRECONFIG is specified but the correct registry information cannot be located, InternetOpen reverts to INTERNET_OPEN_TYPE_DIRECT, that is, it attempts to connect to the server directly.


< BACK  NEXT >


Windows CE 3. 0 Application Programming
Windows CE 3.0: Application Programming (Prentice Hall Series on Microsoft Technologies)
ISBN: 0130255920
EAN: 2147483647
Year: 2002
Pages: 181

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net