iPhone中Http请求/响应的API
在iPhone应用程序中,是否仅使用iPhone中Http请求/响应的API,iphone,objective-c,ios,cocoa-touch,nsurlconnection,Iphone,Objective C,Ios,Cocoa Touch,Nsurlconnection,在iPhone应用程序中,是否仅使用NSURLConnections完成所有网络操作??我正在使用NSURLConnections及其委托方法connectionIDReceiverResponse,connectionIDFinishLoading等下载文件 我的问题是NSURLConnectionAPI是否仅在cocoa touch中可用于Http请求/响应?是否有其他可用的API 我们可以使用NSURLConnection上传文件吗 我想有很多问题,但我真的很困惑。请帮帮我 我也觉得用NS
NSURLConnections
完成所有网络操作??我正在使用NSURLConnections及其委托方法connectionIDReceiverResponse
,connectionIDFinishLoading
等下载文件
我的问题是NSURLConnection
API是否仅在cocoa touch中可用于Http请求/响应?是否有其他可用的API
我们可以使用NSURLConnection
上传文件吗
我想有很多问题,但我真的很困惑。请帮帮我 我也觉得用
NSURLConnection
上传文件很困难。最后,我使用AFNetworking
库。它工作得很好
NSURL *url = [NSURL URLWithString:@"http://api-base-url.com"];
AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:url];
NSData *imageData = UIImageJPEGRepresentation([UIImage imageNamed:@"avatar.jpg"], 0.5);
NSMutableURLRequest *request = [httpClient multipartFormRequestWithMethod:@"POST" path:@"/upload" parameters:nil constructingBodyWithBlock: ^(id <AFMultipartFormData>formData) {
[formData appendPartWithFileData:imageData name:@"avatar" fileName:@"avatar.jpg" mimeType:@"image/jpeg"];
}];
AFHTTPRequestOperation *operation = [[[AFHTTPRequestOperation alloc] initWithRequest:request] autorelease];
[operation start];
NSURL*url=[NSURL URLWithString:@”http://api-base-url.com"];
AFHTTPClient*httpClient=[[AFHTTPClient alloc]initWithBaseURL:url];
NSData*imageData=UIImageJPEG表示法([UIImage ImageName:@“avatar.jpg”],0.5);
NSMutableURLRequest*request=[httpClient multipartFormRequestWithMethod:@“POST”路径:@“/upload”参数:nil constructingBodyWithBlock:^(id
此外,还有CocoaPods管理objective-C的库。我正在尝试使用它
我也觉得用NSURLConnection
上传文件很困难。最后,我使用了AFNetworking
库。它工作得很好
NSURL *url = [NSURL URLWithString:@"http://api-base-url.com"];
AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:url];
NSData *imageData = UIImageJPEGRepresentation([UIImage imageNamed:@"avatar.jpg"], 0.5);
NSMutableURLRequest *request = [httpClient multipartFormRequestWithMethod:@"POST" path:@"/upload" parameters:nil constructingBodyWithBlock: ^(id <AFMultipartFormData>formData) {
[formData appendPartWithFileData:imageData name:@"avatar" fileName:@"avatar.jpg" mimeType:@"image/jpeg"];
}];
AFHTTPRequestOperation *operation = [[[AFHTTPRequestOperation alloc] initWithRequest:request] autorelease];
[operation start];
NSURL*url=[NSURL URLWithString:@”http://api-base-url.com"];
AFHTTPClient*httpClient=[[AFHTTPClient alloc]initWithBaseURL:url];
NSData*imageData=UIImageJPEG表示法([UIImage ImageName:@“avatar.jpg”],0.5);
NSMutableURLRequest*request=[httpClient multipartFormRequestWithMethod:@“POST”路径:@“/upload”参数:nil constructingBodyWithBlock:^(id
此外,还有CocoaPods管理objective-C的库。我正在尝试使用它
您也可以尝试使用MKNetworkKit框架:
易于使用,工作非常好!您也可以尝试使用MKNetworkKit框架:
易于使用,效果非常好!管理网络的最佳方式:Thnks@WhiteTiger,我知道ASIHTTPRequest可用。但我倾向于使用苹果提供的默认API。我同意@WhiteTiger@WhiteTigerASIHTTPRequest现在已经过时了,并没有得到积极的发展。你应该考虑使用。rk:Thnks@WhiteTiger,我知道ASIHTTPRequest是可用的。但我倾向于使用苹果提供的默认API。我同意@WhiteTiger@WhiteTigerASIHTTPRequest现在已经过时,并没有得到积极的发展。你应该考虑使用。