上载plist文件

时间:2018-10-15 07:44:28

标签: php objective-c

我是2018-10-15 24:00的新手。我正在尝试将我的(空)plist上传到服务器进行测试。这是我的Objective-C代码:

objective-c

然后在-(void) writeOnce { NSString *one = [[self applicationDocumentsDirectory].path stringByAppendingPathComponent:@"one.plist"]; NSString *two = [[self applicationDocumentsDirectory].path stringByAppendingPathComponent:@"two.plist"]; [@"{}" writeToFile:one atomically:YES encoding:NSUTF8StringEncoding error:nil]; [@"{}" writeToFile:two atomically:YES encoding:NSUTF8StringEncoding error:nil]; } 上致电viewDidLoad() 之后。我使用以下文件上传文件:

[self writeOnce];

我的NSString * plistPath = [[self applicationDocumentsDirectory].path stringByAppendingPathComponent:@"one.plist"]; [self uploadLog:plistPath]; 无效:

uploadLog()

但是。得到这个:

  

线程3:EXC_BAD_ACCESS(代码= 1,地址= 0x0)

- (void) uploadLog :(NSString *) filePath { NSData *data = [[NSData alloc] initWithContentsOfFile:filePath]; NSString *urlString =[NSString stringWithFormat:@"server.com/upload.php"]; NSError *error; NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration]; NSURLSession *session = [NSURLSession sessionWithConfiguration:configuration delegate:self delegateQueue:nil]; NSURL *url = [NSURL URLWithString:urlString]; NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0]; [request addValue:@"application/json" forHTTPHeaderField:@"Content-Type"]; [request addValue:@"application/json" forHTTPHeaderField:@"Accept"]; [request setHTTPMethod:@"POST"]; // NSData *postData = [NSJSONSerialization dataWithJSONObject:data options:0 error:&error]; // error NSData *postData =[NSJSONSerialization JSONObjectWithData:data options:0 error:&error]; [request setHTTPBody:postData]; NSURLSessionDataTask *postDataTask = [session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) { NSLog(response,error); }]; [postDataTask resume]; } 代码:

upload.php

enter image description here

0 个答案:

没有答案