




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
ASIHTTPRequestHTTP異步請求,隊列請求,GZIP壓縮,緩存,斷點(diǎn)續(xù)傳,進(jìn)度跟蹤,上傳文獻(xiàn),HTTP認(rèn)證Objective-CBlockAPIHang住而不響應(yīng)任何顧客事件。因此,(下面會講到)-{NSURL*url=[NSURLASIHTTPRequest*request=[ASIHTTPRequestrequestWithURL:url];[requeststartSynchronous];NSError*error=[requesterror];if(!error){NSString*response=[request}}a,requestWithURLASIHTTPRequest的一種實(shí)例b,startSynchronous辦法啟動同時訪問,c,requesterror屬性獲取錯誤信息。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來啟動網(wǎng)絡(luò)請求。bdelegaterequestFinished,請求失敗時(如網(wǎng)絡(luò)問題或服務(wù)器內(nèi)部錯誤)requestFailed。maxConcurrentOperationCount時,請求實(shí)例將被置為等待,直到前面最少有一種請求完畢并優(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ù)隊列。我們通ASIHTTPRequest.hNSOperation的子類。也就是說它userInfobsetDidFinishSelectorsetDidFailSelector的回調(diào)辦法cASIHTTPRequestrequestFinished:與failWithProblem:辦法ASINetworkQueues,delegaterequestdeleaget。中其實(shí)并不能執(zhí)行請求,只有調(diào)用queuego]才會執(zhí)行;一種正在運(yùn)行中的隊列,并不需要重復(fù)調(diào)用[queuego]。默認(rèn)狀況下,隊列中的一種請求如果失敗,它會取消全部未完畢的請求。能夠設(shè)立queuesetShouldCancelAllRequestsOnFailure:NO]來修正。另一方面,不管是隊列請求,還是簡樸的異步請求,全部調(diào)用[requestcancel]delegate辦法,則設(shè)立:request如果只想取消一種請求,能夠設(shè)立隊列:queuesetShouldCancelAllRequestsOnFailure:NO如果想明確取消全部請求:queuecancelAllOperationsdelegatedelegate-{[requestclearDelegatesAndCancel];[requestrelease];[super}ASIFormDataRequestFormHeader會自動識別。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目錄下。如果下載完畢會做下列事1downloadDestinationPath目錄中,臨時文獻(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會自動保存訪問過的URL信息,并備之后用。在下列幾個場景非常有用:ASIDownloadCacheGet請求的響應(yīng)數(shù)據(jù)進(jìn)行緩存(200請求[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會先判斷與否存在緩存數(shù)據(jù)。a,如果沒有再進(jìn)行網(wǎng)絡(luò)請求。b,如果存,request將被取消(沒有錯誤信息)(這個在解決異常時非常有用你能夠設(shè)立緩存的數(shù)據(jù)需要保存多長時間,ASIHTTPRequest提供了兩種方略:儲。當(dāng)下次運(yùn)行或[ASIHTTPRequestclearSession]時,緩存將失效。ASIHTTPRequest*request=[ASIHTTPRequestrequestWithURL:url[requestsetCacheStoragePolicy:ASICachePermanentlyCacheStoragePolicy];clearCachedResponsesForStoragePolicyHeader[[ASIDownloadCachesharedCache]setShouldRespectCacheControlHeaders:NO];request緩存的有效時間[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等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 二零二五家庭房產(chǎn)分配與共有權(quán)轉(zhuǎn)讓及子女贍養(yǎng)協(xié)議
- 二零二五年度房屋無償贈與及環(huán)保改造合同
- 二零二五年度可再生能源電工員工合作協(xié)議
- 二零二五年度房屋買賣及室內(nèi)空氣凈化服務(wù)合同
- 二零二五年度公司管理人員健康管理與聘用合同
- 2025年度輔導(dǎo)班家長學(xué)生國際視野拓展協(xié)議
- 2025年度物流合同賬戶變更補(bǔ)充協(xié)議
- 二零二五年度個人與企業(yè)民間借貸合同模板
- 二零二五年度房產(chǎn)租賃權(quán)轉(zhuǎn)讓與租賃合同續(xù)簽通知協(xié)議
- 二零二五年度企業(yè)購房擔(dān)保服務(wù)合同
- 子宮內(nèi)膜癌教學(xué)查房
- 預(yù)防深靜脈血栓VTE持續(xù)改進(jìn)QCC品管圈PDCA案例3例
- 水環(huán)境綜合治理服務(wù)方案(技術(shù)標(biāo))
- 【原創(chuàng)】頭腦特工隊開的那些心理學(xué)腦洞
- 美甲藝術(shù)全套教學(xué)課件
- 高等數(shù)學(xué)上冊目錄同濟(jì)第七版
- 中國古代餐具
- 電動執(zhí)行機(jī)構(gòu)安裝施工工藝標(biāo)準(zhǔn)
- 施工日志模板
- 粗原料氣的凈化-二氧化碳的脫除(合成氨生產(chǎn))
- Agilent7820A氣相色譜儀操作規(guī)程知識講解
評論
0/150
提交評論