Iphone AFHTTPClient不发送完整数据
我使用下面的代码发送一个wav文件,但是,该过程在Iphone AFHTTPClient不发送完整数据,iphone,afhttpclient,Iphone,Afhttpclient,我使用下面的代码发送一个wav文件,但是,该过程在 Sent 131072 of 141359 bytes 那么?代码有问题吗?还是我遗漏了什么 NSString *vidURL = [[NSBundle mainBundle] pathForResource:@"M1F1-int24WE-AFsp" ofType:@"wav"]; NSData *videoData = [NSData dataWithContentsOfURL:[NSURL fil
Sent 131072 of 141359 bytes
那么?代码有问题吗?还是我遗漏了什么
NSString *vidURL = [[NSBundle mainBundle] pathForResource:@"M1F1-int24WE-AFsp" ofType:@"wav"];
NSData *videoData = [NSData dataWithContentsOfURL:[NSURL fileURLWithPath:vidURL]];
NSURL *url = [NSURL URLWithString:@"http://apps2.mobiiworld.com"];
AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:url];
// NSData *imageData = UIImageJPEGRepresentation([UIImage imageNamed:@"Romantic.jpg"], 0.5);
NSMutableURLRequest *request = [httpClient multipartFormRequestWithMethod:@"POST" path:@"/staging/krafttesting/upload.php" parameters:nil constructingBodyWithBlock: ^(id <AFMultipartFormData>formData) {
[formData appendPartWithFileData:videoData name:@"file" fileName:@"recording.wav" mimeType:@"audio/vnd.wave"];
}];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
[operation setUploadProgressBlock:^(NSUInteger bytesWritten, long long totalBytesWritten, long long totalBytesExpectedToWrite) {
NSLog(@"Sent %lld of %lld bytes", totalBytesWritten, totalBytesExpectedToWrite);
}];
// [httpClient enqueueHTTPRequestOperation:operation];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {NSLog(@"Success");}
failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"error: %@", operation.responseString);
NSLog(@"error: %@", error.userInfo);
}];
[operation start];
NSString*vidURL=[[NSBundle mainBundle]路径用于资源:@“wav”类型的“M1F1-int24WE-AFsp”;
NSData*videoData=[NSData DATA WITH CONTENTS OFURL:[NSURL fileURLWithPath:vidURL]];
NSURL*url=[NSURL URLWithString:@”http://apps2.mobiiworld.com"];
AFHTTPClient*httpClient=[[AFHTTPClient alloc]initWithBaseURL:url];
//NSData*imageData=UIImageJPEG表示法([UIImage ImageName:@“romatic.jpg”],0.5);
NSMutableURLRequest*request=[httpClient multipartFormRequestWithMethod:@“POST”路径:@“/staging/krafttesting/upload.php”参数:nil constructingBodyWithBlock:^(id formData){
[formData appendPartWithFileData:videoData名称:@“file”文件名:@“recording.wav”mimeType:@“audio/vnd.wave”];
}];
AFHTTPRequestOperation*操作=[[AFHTTPRequestOperation alloc]initWithRequest:request];
[操作设置LoadProgressBlock:^(NSUTEGER字节写入、long long TotalBytesWrite、long long totalBytesExpectedToWrite){
NSLog(@“已发送%lld个字节,共%lld个字节”,TotalBytesWrite,totalBytesExpectedToWrite);
}];
//[httpClient排队HttpRequestOperation:operation];
[操作setCompletionBlockWithSuccess:^(AFHTTPRequestOperation*操作,id响应对象){NSLog(@“Success”);}
失败:^(AFHTTPRequestOperation*操作,NSError*错误){
NSLog(@“错误:%@”,操作。响应字符串);
NSLog(@“error:%@”,error.userInfo);
}];
[操作启动];
我找到了解决方案。似乎只有在ARC打开时,AFHTTPClient才能工作。我关闭了ARC,因此它无法工作-尽管我没有收到任何错误。为了找出问题所在,我们需要尽可能多的信息。因此,等待连接完成(可能超时),并记录错误和任何其他重要信息:响应的状态代码和响应数据(如果有),记录或从AFN返回的任何错误消息。连接从不超时。应用程序只是挂起,什么也没发生。为了找到问题,我把它保存了一夜。但连接从未超时。它最终必须超时,或者以响应结束。让它在调试器中运行。然后,当程序出现挂起时,通过“调试器”窗格中的“停止”按钮(看起来像[| |])中断程序。然后单击navigator区域中的thread视图,查看每个线程暂停的位置。这将揭示更多信息。