iPhone應(yīng)用ASIFormDataRequest POST操作架構(gòu)設(shè)計
iPhone應(yīng)用ASIFormDataRequest POST操作架構(gòu)設(shè)計是本文要介紹的內(nèi)容,教你如何學(xué)習(xí)iphone應(yīng)用開發(fā)架構(gòu)的設(shè)計。不多說,來看詳細(xì)內(nèi)容。
//開啟iphone網(wǎng)絡(luò)開關(guān)
- [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
- ASIFormDataRequest *request = [[ASIFormDataRequest alloc] initWithURL:[NSURLURLWithString:host]];
//超時時間
- request.timeOutSeconds = 30;
//定義異步方法
- [request setDelegate:self];
- [request setDidFailSelector:@selector(requestDidFailed:)];
- [request setDidFinishSelector:@selector(requestDidSuccess:)];
//用戶自定義數(shù)據(jù) 字典類型 (可選)
- request.userInfo = [NSDictionary dictionaryWithObject:method forKey:@"Method"];
//post的數(shù)據(jù)
- [request appendPostData:[body dataUsingEncoding:NSUTF8StringEncoding]];
//開始執(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è)計 自選)
- [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{
//獲取的用戶自定義內(nèi)容
- NSString *method = [request.userInfo objectForKey:@"Method"];
小結(jié):iPhone應(yīng)用ASIFormDataRequest POST操作架構(gòu)設(shè)計的內(nèi)容介紹完了,希望通過本文的學(xué)習(xí)能對你有所幫助!