![ASIHTTPRequest詳解http請(qǐng)求終結(jié)者_(dá)第1頁](http://file4.renrendoc.com/view10/M03/2E/17/wKhkGWWzKe-Abq2hAAHN7mM9jkE543.jpg)
![ASIHTTPRequest詳解http請(qǐng)求終結(jié)者_(dá)第2頁](http://file4.renrendoc.com/view10/M03/2E/17/wKhkGWWzKe-Abq2hAAHN7mM9jkE5432.jpg)
![ASIHTTPRequest詳解http請(qǐng)求終結(jié)者_(dá)第3頁](http://file4.renrendoc.com/view10/M03/2E/17/wKhkGWWzKe-Abq2hAAHN7mM9jkE5433.jpg)
![ASIHTTPRequest詳解http請(qǐng)求終結(jié)者_(dá)第4頁](http://file4.renrendoc.com/view10/M03/2E/17/wKhkGWWzKe-Abq2hAAHN7mM9jkE5434.jpg)
![ASIHTTPRequest詳解http請(qǐng)求終結(jié)者_(dá)第5頁](http://file4.renrendoc.com/view10/M03/2E/17/wKhkGWWzKe-Abq2hAAHN7mM9jkE5435.jpg)
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
ASIHTTPRequestHTTP異步請(qǐng)求,隊(duì)列請(qǐng)求,GZIP壓縮,緩存,斷點(diǎn)續(xù)傳,進(jìn)度跟蹤,上傳文獻(xiàn),HTTP認(rèn)證Objective-CBlockAPIHang住而不響應(yīng)任何顧客事件。因此,(下面會(huì)講到)-{NSURL*url=[NSURLASIHTTPRequest*request=[ASIHTTPRequestrequestWithURL:url];[requeststartSynchronous];NSError*error=[requesterror];if(!error){NSString*response=[request}}a,requestWithURLASIHTTPRequest的一種實(shí)例b,startSynchronous辦法啟動(dòng)同時(shí)訪問,c,requesterror屬性獲取錯(cuò)誤信息。d,responseStringNSString信息。-{NSURL*url=[NSURLASIHTTPRequest*request=[ASIHTTPRequestrequestWithURL:url];[requestsetDelegate:self];[request}-(void)requestFinished:(ASIHTTPRequest{//UsewhenfetchingtextNSString*responseString=[request//UsewhenfetchingbinaryNSData*responseData=[request}-(void)requestFailed:(ASIHTTPRequest{NSError*error=[request}a,與上面不同的地方是指定了一種"delegate"startAsynchronous來啟動(dòng)網(wǎng)絡(luò)請(qǐng)求。bdelegaterequestFinished,請(qǐng)求失敗時(shí)(如網(wǎng)絡(luò)問題或服務(wù)器內(nèi)部錯(cuò)誤)requestFailed。maxConcurrentOperationCount時(shí),請(qǐng)求實(shí)例將被置為等待,直到前面最少有一種請(qǐng)求完畢并優(yōu)),maxConcurrentOperationCount設(shè)為“1”。-{if(![selfqueue])[selfsetQueue:[[[NSOperationQueuealloc]init]}NSURL*url=[NSURLASIHTTPRequest*request=[ASIHTTPRequestrequestWithURL:url];[requestsetDelegate:self];[requestsetDidFinishSelector:@selector(requestDone:)];[requestsetDidFailSelector:@selector(requestWentWrong:)];[[selfqueue]addOperation:request];//queueisan}-(void)requestDone:(ASIHTTPRequest{NSString*response=[request}-(void)requestWentWrong:(ASIHTTPRequest{NSError*error=[request}NSOperationQueueCocoa架構(gòu)的執(zhí)行任務(wù)(NSOperation)的任務(wù)隊(duì)列。我們通ASIHTTPRequest.hNSOperation的子類。也就是說它userInfobsetDidFinishSelectorsetDidFailSelector的回調(diào)辦法cASIHTTPRequestrequestFinished:與failWithProblem:辦法ASINetworkQueues,delegaterequestdeleaget。中其實(shí)并不能執(zhí)行請(qǐng)求,只有調(diào)用queuego]才會(huì)執(zhí)行;一種正在運(yùn)行中的隊(duì)列,并不需要重復(fù)調(diào)用[queuego]。默認(rèn)狀況下,隊(duì)列中的一種請(qǐng)求如果失敗,它會(huì)取消全部未完畢的請(qǐng)求。能夠設(shè)立queuesetShouldCancelAllRequestsOnFailure:NO]來修正。另一方面,不管是隊(duì)列請(qǐng)求,還是簡(jiǎn)樸的異步請(qǐng)求,全部調(diào)用[requestcancel]delegate辦法,則設(shè)立:request如果只想取消一種請(qǐng)求,能夠設(shè)立隊(duì)列:queuesetShouldCancelAllRequestsOnFailure:NO如果想明確取消全部請(qǐng)求:queuecancelAllOperationsdelegatedelegate-{[requestclearDelegatesAndCancel];[requestrelease];[super}ASIFormDataRequestFormHeader會(huì)自動(dòng)識(shí)別。ASIFormDataRequest*request=[ASIFormDataRequestrequestWithURL:url];[requestsetPostValue:@"Ben"forKey:@"first_name"];[requestsetPostValue:@"Copsey"[requestsetFile:@"/Users/ben/Desktop/ben.jpg"[requestaddData:imageDatawithFileName:@"george.jpg"andContentType:@"image/jpeg"forKey:@"photos"];ASIHTTPRequest*request=[ASIHTTPRequest[requestappendPostData:[@"Thisismydata"http://DefaultbecomesPOSTwhenyouuseappendPostData:/appendPostDataFromFile:/setPostBody:[requestrequestsetDownloadDestinationPath,能夠設(shè)立下載文獻(xiàn)用的下載目的目錄。temporaryFileDownloadPath目錄下。如果下載完畢會(huì)做下列事1downloadDestinationPath目錄中,臨時(shí)文獻(xiàn)信息:statusheader[request[[requestresponseHeaders]objectForKey:@"X-Powered-By"];[requestresponseEncoding];cookieCookieNSHTTPCookieStorage你能夠用[ASIHTTPRequestsetSessionCookies:nil];Cookies。Cookie//CreateaNSDictionary*properties=[[[NSMutableDictionaryalloc]init][propertiessetValue:[@"TestValue"encodedCookieValue][propertiessetValue:@"ASIHTTPRequestTestCookie"[propertiessetValue:@"."[propertiessetValue:[NSDatedateWithTimeIntervalSinceNow:60*60][propertiessetValue:@"/asi-http-request/tests"NSHTTPCookie*cookie=[[[NSHTTPCookiealloc]initWithProperties:properties]autorelease];//Thisurlwillreturnthevalueofthe'ASIHTTPRequestTestCookie'cookieurl=[NSURLURLWithString:@""];request=[ASIHTTPRequestrequestWithURL:url];[requestsetUseCookiePersistence:NO];[requestsetRequestCookies:[NSMutableArrayarrayWithObject:cookie]];[requeststartSynchronous];//Shouldbe:Ihave'TestValue'asthevalueofNSLog(@"%@",[request0.94[requestsetAllowResumeForFileDownloads:YES[requestsetDownloadDestinationPath:downloadPathASIHTTPRequest會(huì)自動(dòng)保存訪問過的URL信息,并備之后用。在下列幾個(gè)場(chǎng)景非常有用:ASIDownloadCacheGet請(qǐng)求的響應(yīng)數(shù)據(jù)進(jìn)行緩存(200請(qǐng)求[ASIHTTPRequestsetDefaultCache:[ASIDownloadCacheASIHTTPRequest*request=[ASIHTTPRequestrequestWithURL:url];[requestsetDownloadCache:[ASIDownloadCachesharedCache]];request實(shí)例中:[cachesetStoragePath:@"/Users/ben/Documents/Cached-Downloads"];[selfsetMyCache:cache];ASIHTTPRequest*request=[ASIHTTPRequestrequestWithURL:url];[requestsetDownloadCache:[selfmyCache]];默認(rèn)緩存行為,request會(huì)先判斷與否存在緩存數(shù)據(jù)。a,如果沒有再進(jìn)行網(wǎng)絡(luò)請(qǐng)求。b,如果存,request將被取消(沒有錯(cuò)誤信息)(這個(gè)在解決異常時(shí)非常有用你能夠設(shè)立緩存的數(shù)據(jù)需要保存多長(zhǎng)時(shí)間,ASIHTTPRequest提供了兩種方略:儲(chǔ)。當(dāng)下次運(yùn)行或[ASIHTTPRequestclearSession]時(shí),緩存將失效。ASIHTTPRequest*request=[ASIHTTPRequestrequestWithURL:url[requestsetCacheStoragePolicy:ASICachePermanentlyCacheStoragePolicy];clearCachedResponsesForStoragePolicyHeader[[ASIDownloadCachesharedCache]setShouldRespectCacheControlHeaders:NO];request緩存的有效時(shí)間[requestsetSecondsToCache:60*60*24*30];30[requestdidUseCachedResponse[requestsetDownloadDestinationPath:[[ASIDownloadCachesharedCache]pathToStoreCachedResponseDataForRequest:request]];ASICacheDelegate默認(rèn)的狀況下,ASIHTTPRequesthttp//ConfigureaproxyservermanuallyNSURL*url=[NSURLURLWithString:@""];ASIHTTPRequest*request=[ASIHTTPRequestrequestWithURL:url];[requestsetProxyHost:@""];[requestsetProxyPort:3128//Alternatively,youcanuseamanually-specifiedProxyAutoConfigfile//(It'sprobablybestifyouusealocal[requestsetPACurl:[NSURLASIHTTPRequest,iOS4[requestsetShouldContinueWhenAppEntersBackground:YES[ASIHTTPRequestisNetworkInUsestatusbar[ASIHTTPRequestsetShouldUpdateNetworkActivityIndicator:NO[request
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 個(gè)性化咖啡館裝修合同模板
- 親子酒店陽臺(tái)裝修合同
- 民宿藝術(shù)館裝修合同范本
- 機(jī)械設(shè)備物流合同范本
- 長(zhǎng)寧防靜電地坪施工方案
- 合同范本政府蓋章
- 公寓短租租房合同范例
- 新都地標(biāo)性酒店施工方案
- 加工合同包括些合同范例
- 提振餐飲消費(fèi)的創(chuàng)新策略與實(shí)踐方案
- 2025年首都機(jī)場(chǎng)集團(tuán)公司招聘筆試參考題庫(kù)含答案解析
- 2025云南省貴金屬新材料控股集團(tuán)限公司面向高校畢業(yè)生專項(xiàng)招聘144人高頻重點(diǎn)提升(共500題)附帶答案詳解
- 蘇州市區(qū)2024-2025學(xué)年五年級(jí)上學(xué)期數(shù)學(xué)期末試題一(有答案)
- 暑期預(yù)習(xí)高一生物必修二知識(shí)點(diǎn)
- 醫(yī)藥高等數(shù)學(xué)知到智慧樹章節(jié)測(cè)試課后答案2024年秋浙江中醫(yī)藥大學(xué)
- 2024年濰坊工程職業(yè)學(xué)院?jiǎn)握新殬I(yè)適應(yīng)性測(cè)試題庫(kù)完美版
- GB/T 44823-2024綠色礦山評(píng)價(jià)通則
- 人教版英語高考試卷與參考答案(2024年)
- 河砂、碎石生產(chǎn)質(zhì)量保證措施方案
- 三位數(shù)除以兩位數(shù)過關(guān)練習(xí)口算題大全附答案
- 紅樓夢(mèng)服飾文化
評(píng)論
0/150
提交評(píng)論