Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/43.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
iPhone中Http请求/响应的API_Iphone_Objective C_Ios_Cocoa Touch_Nsurlconnection - Fatal编程技术网

iPhone中Http请求/响应的API

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

在iPhone应用程序中,是否仅使用
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现在已经过时,并没有得到积极的发展。你应该考虑使用。