ASIHTTPRequest detects the proxy settings of the system and automatically uses the proxy for request. Starting from version 1.0.6, it also supports the PAC file and the proxy that requires authorization.
By default, ASIHTTPRequest will attempt to automatically detect proxy settings. Of course, you can view your manual settings:
- // Manually set the Proxy Server
- NSURL * url = [NSURL URLWithString: @ "http://www.dreamingwish.com"];
- ASIHTTPRequest * request = [ASIHTTPRequest requestWithURL: url];
- [Request setProxyHost: @ "192.168.0.1"];
- [Request setProxyPort: 3128];
-
- // Another method is to use the agent to configure the script file
- // (It is best to use a local pac file)
- [Request setPACurl: [NSURL URLWithString: @ "path/to/test. pac"];
Proxy requiring authorization
On Mac OS, ASIHTTPRequest can automatically detect the creden of the proxy that requires authorization, provided that the creden。 are set in system settings ). On iOS, ASIHTTPRequest cannot automatically detect authorization creden。. Therefore, you must manually use delegate to obtain the appropriate creden。 from your controller or user, or ask ASIAuthenticationDialog to obtain credenalog from the user. Once a valid proxy credential is obtained, the credential is stored in keychian only if useKeychainPersistence is enabled.
Manually specify creden for proxy
- NSURL * url = [NSURL URLWithString: @ "http://www.dreamingwish.com"];
- ASIHTTPRequest * request = [ASIHTTPRequest requestWithURL: url];
- [Request setProxyHost: @ "192.168.0.1"];
- [Request setProxyPort: 3128];
-
- // Set username and password for the proxy that requires authorization
- [Request setProxyUsername: @ "bencopsey"];
- [Request setProxyPassword: @ "password"];
-
- // For NTLM proxy, you also need to set domain (NTLM proxy function is not tested)
- [Request setProxyDomain: @ "la. la. land"];
Use delegate to provide proxy credenproxy
The working principle of this feature is the same as that of "using delegate to provide HTTP Authorization". There is only one difference: Your delegate must respond to the proxyAuthenticationNeededForRequest: function.
Use the built-in authorization dialog box only for iOS)
This feature is attributed to the new ASIAuthenticationDialog class of version 1.0.8. Used to obtain creden。 from the user to authorize webserver or proxy.
If your delegate does not respond to the proxyAuthenticationNeededForRequest: function, ASIHTTPRequest will display a prompt to the customer asking the user to enter the authorization credential by default. With ASIHTTPRequest, developers no longer need to write additional code to display the authorization dialog box, because ASIHTTPRequest will display it by default.
The proxy authorization dialog box is not displayed when synchronous request is used.
If you do not limit the use of the proxy authorization dialog box, you can either implement proxyAuthenticationNeededForRequest:, or set shouldPresentProxyAuthenticationDialog to false. In this case, your program cannot connect to the proxy ). To change the style of the dialog box, you must inherit the ASIHTTPRequest class and override showProxyAuthenticationDialog to display your own dialog box or ASIAuthenticationDialog subclass.