相关疑难解决方法(0)

如何使用AFNetworking管理会话?

正如标题所暗示的,我在一个iOS项目中使用AFNetworking,其中应用程序与服务器通信.当用户登录时,服务器通过发回成功标志来响应,并且响应头包含会话ID.

我想知道AFNetworking是否会在每次后续请求时自动发送会话ID,还是我应该以某种方式自行处理?

为了您的信息,我无法控制请求的身份验证后端.我只是在构建一个与服务器通信的客户端.

cookies session ios afnetworking

55
推荐指数
1
解决办法
3万
查看次数

使用AFNetworking POST jpeg上传

我不能为我的生活弄清楚为什么当我使用AFNetworking时这不起作用.它与ASIHTTP合作.这对我来说都很新鲜.但我无法弄清楚为什么文件不会从$ _FILES转移到服务器的HD了.这是iOS代码:

- (IBAction)uploadPressed 
{
[self.fileName resignFirstResponder];
NSURL *remoteUrl = [NSURL URLWithString:@"http://mysite.com"];

NSTimeInterval timeInterval = [NSDate timeIntervalSinceReferenceDate];
NSString *photoName=[NSString stringWithFormat:@"%lf-Photo.jpeg",timeInterval];

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];

// the path to write file
NSString *filePath = [documentsDirectory stringByAppendingPathComponent:photoName];
NSData * photoImageData = UIImageJPEGRepresentation(self.remoteImage.image, 1.0);
[photoImageData writeToFile:filePath atomically:YES];

NSLog(@"photo written to path: e%@", filePath);

AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:remoteUrl];
NSMutableURLRequest *afRequest = [httpClient multipartFormRequestWithMethod:@"POST" 
                                                                       path:@"/photos" 
                                                                 parameters:nil 
                                                  constructingBodyWithBlock:^(id <AFMultipartFormData>formData) 
                                  {
                                      [formData appendPartWithFormData:[self.fileName.text dataUsingEncoding:NSUTF8StringEncoding] 
                                                                  name:@"name"];


                                      [formData appendPartWithFileData:photoImageData 
                                                                  name:self.fileName.text …
Run Code Online (Sandbox Code Playgroud)

php iphone http objective-c afnetworking

10
推荐指数
2
解决办法
2万
查看次数

标签 统计

afnetworking ×2

cookies ×1

http ×1

ios ×1

iphone ×1

objective-c ×1

php ×1

session ×1