iPhone應(yīng)用ASIFormDataRequest POST操作架構(gòu)設(shè)計(jì)
iPhone應(yīng)用ASIFormDataRequest POST操作架構(gòu)設(shè)計(jì)是本文要介紹的內(nèi)容,教你如何學(xué)習(xí)iphone應(yīng)用開(kāi)發(fā)架構(gòu)的設(shè)計(jì)。不多說(shuō),來(lái)看詳細(xì)內(nèi)容。
//開(kāi)啟iphone網(wǎng)絡(luò)開(kāi)關(guān)
- [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
- ASIFormDataRequest *request = [[ASIFormDataRequest alloc] initWithURL:[NSURLURLWithString:host]];
//超時(shí)時(shí)間
- request.timeOutSeconds = 30;
//定義異步方法
- [request setDelegate:self];
- [request setDidFailSelector:@selector(requestDidFailed:)];
- [request setDidFinishSelector:@selector(requestDidSuccess:)];
//用戶(hù)自定義數(shù)據(jù) 字典類(lèi)型 (可選)
- request.userInfo = [NSDictionary dictionaryWithObject:method forKey:@"Method"];
//post的數(shù)據(jù)
- [request appendPostData:[body dataUsingEncoding:NSUTF8StringEncoding]];
//開(kāi)始執(zhí)行
- [request startAsynchronous];
//執(zhí)行成功
- - (void)requestDidSuccess:(ASIFormDataRequest *)request
- {
//獲取頭文件
- NSDictionary *headers = [request responseHeaders];
//獲取http協(xié)議執(zhí)行代碼
- NSLog(@"Code:%d",[request responseStatusCode]);
- if ([delegaterespondsToSelector:@selector(OARequestSuccessed:withResponse:WithData:withHeaders:)])
- {
//執(zhí)行委托操作 (架構(gòu)設(shè)計(jì) 自選)
- [delegate OARequestSuccessed:method withResponse:[request responseString]WithData:[request responseData] withHeaders:headers];
- }
//清空
- if (request)
- {
- [request release];
- }
//關(guān)閉網(wǎng)絡(luò)
- [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
- }
//執(zhí)行失敗
- - (void)requestDidFailed:(ASIFormDataRequest *)request{
//獲取的用戶(hù)自定義內(nèi)容
- NSString *method = [request.userInfo objectForKey:@"Method"];
小結(jié):iPhone應(yīng)用ASIFormDataRequest POST操作架構(gòu)設(shè)計(jì)的內(nèi)容介紹完了,希望通過(guò)本文的學(xué)習(xí)能對(duì)你有所幫助!