PLUSNative: Adding Support for Proxy Servers

In many environments, it may be necessary for your application to support proxy servers. This topic shows you how to set proxy server information in PLUSNative, and also summarizes some methods of automatically obtaining some of this information.

Important Note

Proxy authentication is only supported by PLUSNative with plain-HTTP requests.  If you attempt to make an SSL request, PLUSNative will automatically attempt to fall-back to a plain-HTTP request (unless the SK_FLAGS_REQUIRE_SSL flag was specified in the API Context or function call). Although SSL is preferred, the web service requests are typically encrypted.  If you are not encrypting the web service requests, however, this means all of the data will be transmitted as plain-text when proxy authentication is used.

Using a specified proxy server

During application initialization, you always configure an API Context. This the most opportune time for your application to set proxy server information using the SK_ApiContextSetFieldString function, as doing this will allow PLUSNative to use this information for any web service calls made with that API Context. The code you would add to configure proxy settings could resemble the following:

C/C++
//Your call to SK_ApiContextInitialize comes before the following code.
//refer to the Configuring the API Context topic for instructions

SK_ApiContextSetFieldString(context, SK_FLAGS_NONE, (SK_ApiContext_StringFields)SK_APICONTEXT_WEBSERVICE_PROXY, "[host]:[port]");
SK_ApiContextSetFieldString(context, SK_FLAGS_NONE, (SK_ApiContext_StringFields)SK_APICONTEXT_WEBSERVICE_PROXYUSERNAME, "[username]");
SK_ApiContextSetFieldString(context, SK_FLAGS_NONE, (SK_ApiContext_StringFields)SK_APICONTEXT_WEBSERVICE_PROXYPASSWORD, "[password]");
Visual Basic
//Your call to SK_ApiContextInitialize comes before the following code.
//refer to the Configuring the API Context topic for instructions
SK_ApiContextSetFieldString(context, SK_FLAGS_NONE, SK_ApiContext_StringFields.SK_APICONTEXT_WEBSERVICE_PROXY, "[host]:[port]")
SK_ApiContextSetFieldString(context, SK_FLAGS_NONE, SK_ApiContext_StringFields.SK_APICONTEXT_WEBSERVICE_PROXYUSERNAME, "[username]")
SK_ApiContextSetFieldString(context, SK_FLAGS_NONE, SK_ApiContext_StringFields.SK_APICONTEXT_WEBSERVICE_PROXYPASSWORD, "[password]")

In the literals used in the example code excerpts above, [host] will reflect the host name/address of the proxy server, and [port] will reflect the proxy server port. Likewise, [username] and [password] will reflect the proxy authentication credentials entered by the application's end-user (and you may need to add dialogs to prompt for this information).

Proxy Auto-Configuration (PAC) scripts

Proxy Auto-Configuration (PAC) scripts are JavaScript files, which are typically interpreted by the user's web browser to automatically determine what proxy server host name/address and port should be used, if any. These files usually reside at a URL, which can be used to download the contents of the PAC scripts.

Parsing PAC Scripts

PLUSNative does not offer any built-in support for parsing these files; however, there are several methods for doing this; however, this section is designed to help point you in the right direction.

Microsoft Windows Platforms

In Microsoft Windows, the URL can be identified by Internet Explorer settings (you can refer to the HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings key, which contains an AutoConfigURL value when one is configured for Internet Explorer) or Active Directory policy. However, parsing the key only provides the URL to the PAC script, so another option is to consider using the WinHttpGetProxyForUrl function, which will also parse the PAC script.

Apple OS X Platforms

Apple offers its own CFProxySupport API, which you may use for obtaining proxy configuration settings and parsing PAC scripts.

Platform Agnostic Approaches

If you need to support other platforms not mentioned above, or you wish to have a single, platform agnostic approach, then you may want to consider adding support for users to enter and store proxy configuration information in your application. If you wish to support PAC scripts via a platform agnostic approach, you could consider allowing users to enter the PAC script URL.  You would then be able to use the SK_HttpRequest function to download the contents of the PAC script from the specified URL. From there, you may consider using a third-party library (such as pacparser) to obtain the proxy host name/address and port.