自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

iOS開發(fā)ASIHTTPRequest使用代理連接

移動(dòng)開發(fā) iOS
本文為大家介紹了iOS開發(fā)ASIHTTPRequest使用代理連接的內(nèi)容,其中包括要求授權(quán)的proxy,手動(dòng)為proxy指定憑據(jù),使用delegate來提供proxy憑據(jù),使用內(nèi)建的授權(quán)對(duì)話框(僅適用于iOS)等等內(nèi)容。

ASIHTTPRequest檢測(cè)系統(tǒng)的proxy設(shè)置并自動(dòng)將proxy用于request。從1.0.6版本開始,它還支持PAC文件和要求授權(quán)的proxy。

默認(rèn)情況下,ASIHTTPRequest將嘗試自動(dòng)檢測(cè)proxy設(shè)置。當(dāng)然,你可以看自己手動(dòng)設(shè)置:

  1. // 手動(dòng)設(shè)置代理服務(wù)器 
  2. NSURL *url = [NSURL URLWithString:@"http://www.dreamingwish.com"]; 
  3. ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url]; 
  4. [request setProxyHost:@"192.168.0.1"]; 
  5. [request setProxyPort:3128]; 
  6.  
  7. // 另一種方法, 使用代理配置腳本文件 
  8. // (***使用本地pac文件) 
  9. [request setPACurl:[NSURL URLWithString:@"path/to/test.pac"]]; 

要求授權(quán)的proxy

在Mac OS上,ASIHTTPRequest可以自動(dòng)檢測(cè)到要求授權(quán)的proxy的憑據(jù)(前提是在系統(tǒng)設(shè)定中設(shè)置好)。在iOS上,ASIHTTPRequest則無法自動(dòng)檢測(cè)出授權(quán)憑據(jù),所以你要么手動(dòng)使用delegate來向你的controller或者用戶索取合適的憑據(jù),要么讓ASIAuthenticationDialog向用戶索取憑據(jù)。一旦獲得了一個(gè)有效的proxy憑據(jù),那么該憑據(jù)將被存儲(chǔ)到keychian中(前提是啟用useKeychainPersistence )并自動(dòng)重用。

手動(dòng)為proxy指定憑據(jù)

  1. NSURL *url = [NSURL URLWithString:@"http://www.dreamingwish.com"]; 
  2. ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url]; 
  3. [request setProxyHost:@"192.168.0.1"]; 
  4. [request setProxyPort:3128]; 
  5.  
  6. //為要求授權(quán)的proxy設(shè)置username 和password 
  7. [request setProxyUsername:@"bencopsey"]; 
  8. [request setProxyPassword:@"password"]; 
  9.  
  10. // 對(duì)于NTLM proxy,還要設(shè)置 domain (NTLM proxy功能是未經(jīng)測(cè)試的) 
  11. [request setProxyDomain:@"la.la.land"]; 

使用delegate來提供proxy憑據(jù)

這個(gè)特性的工作原理和“使用delegate提供HTTP授權(quán)”一樣,只有一點(diǎn)不同:你的delegate要響應(yīng)proxyAuthenticationNeededForRequest:函數(shù)。

使用內(nèi)建的授權(quán)對(duì)話框(僅適用于iOS)

這個(gè)特性歸功于1.0.8版本的新類ASIAuthenticationDialog 。用來向用戶索取憑據(jù)來授權(quán)webserver或者proxy。

如果你的delegate不響應(yīng)proxyAuthenticationNeededForRequest:函數(shù),那么默認(rèn)情況下,ASIHTTPRequest將會(huì)顯示一個(gè)對(duì)客戶來提示用戶輸入授權(quán)憑據(jù)。使用ASIHTTPRequest,開發(fā)者不再需要寫額外的代碼來顯示授權(quán)對(duì)話框,因?yàn)槟J(rèn)情況下,ASIHTTPRequest就會(huì)顯示它。

使用同步request時(shí)proxy授權(quán)對(duì)話框不會(huì)顯示出來。

如果你不限使用proxy授權(quán)對(duì)話框,那么你要么實(shí)現(xiàn)proxyAuthenticationNeededForRequest:,要么設(shè)置shouldPresentProxyAuthenticationDialog 為false(此時(shí)你的程序?qū)o法連接到proxy)。如果你要改變對(duì)話框的樣式,你得繼承ASIHTTPRequest類,重寫showProxyAuthenticationDialog 來顯示你自己的對(duì)話框或者ASIAuthenticationDialog 子類.

責(zé)任編輯:閆佳明 來源: dreamingwish
相關(guān)推薦

2013-07-22 14:15:17

iOS開發(fā)ASIHTTPRequ

2013-07-22 13:48:55

iOS開發(fā)ASIHTTPRequ使用Cookie

2013-07-22 14:38:00

iOS開發(fā)ASIHTTPRequ

2013-07-21 18:22:59

iOS開發(fā)ASIHTTPRequ

2013-07-21 18:18:00

iOS開發(fā)ASIHttpRequ

2013-07-21 18:27:15

iOS開發(fā)ASIHTTPRequ

2013-07-22 13:54:32

iOS開發(fā)ASIHTTPRequ

2013-07-21 18:32:13

iOS開發(fā)ASIHTTPRequ

2013-07-22 14:25:29

iOS開發(fā)ASIHTTPRequ

2013-07-22 14:43:57

iOS開發(fā)ASIHTTPRequ

2013-07-21 18:09:21

iOS開發(fā)ASIHttpRequ創(chuàng)建和執(zhí)行reques

2013-07-22 14:02:17

iOS開發(fā)ASIHTTPRequ

2013-07-22 14:29:35

iOS開發(fā)ASIHTTPRequ

2013-07-21 18:04:22

ASIHttpRequiOS開發(fā)

2013-03-25 14:13:23

iOSASIHTTPRequ

2011-08-22 10:06:38

IOS開發(fā)ASIHTTPRequHTTP 請(qǐng)求

2013-07-22 14:10:26

iOS開發(fā)ASIHTTPRequ

2011-08-10 17:37:00

iPhoneASIHTTPRequ

2013-07-24 16:47:23

iOS開發(fā)學(xué)習(xí)iOS協(xié)議代理傳值

2011-08-12 13:35:23

iPhone文件流ASIHTTPRequ
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)