我正在尝试将一些数据发送到AFNetworking
到我的服务器,但是当我想发送数据时,控制台日志中出现以下错误,服务器从未收到过数据。
有谁知道我为什么会收到这个错误?
2013-06-06 17:02:16.246 iGym[15255:c07] Stream 0xa267930 is sending an event before being opened
2013-06-06 17:02:17.277 iGym[15255:c07] Inside the success block (null)
代码
-(void) shareExercise {
Exercise* myExercise = [self getCurrentExercise];
if (![myExercise.author isEqualToString:@"me"] )
{
// TODO: Error you cannnot share an exercise that is not yours
}
User* myUser = [self getCurrentUser];
if (myUser.nickname == nil) {
// You need a
}
NSData *exercisePictureThumb = [[NSData alloc] init];
NSData *exerciseDesPic1 = [[NSData alloc] init];
NSData *exercisePic = [[NSData alloc] init];
// Sort the pictures out
if(myExercise.exercisePictureThumb){
UIImage* image1 = [UIImage imageNamed:myExercise.exercisePictureThumb];
exercisePictureThumb = UIImagePNGRepresentation(image1);
}
if(myExercise.exerciseDesPic1){
UIImage* image2 = [UIImage imageNamed:myExercise.exerciseDesPic1];
exerciseDesPic1 = UIImagePNGRepresentation(image2);
}
if(myExercise.exercisePic){
UIImage* image3 = [UIImage imageNamed:myExercise.exercisePic];
exercisePic = UIImagePNGRepresentation(image3);
}
NSDictionary *params = @{@"userID":(myUser.idUserExternal ? myUser.idUserExternal : @"0"),
@"interact":@{
@"action":@"add",
@"actionTarget":@"exercise"},
@"share":@{@"exercise":@{
@"exerciseType":(myExercise.exerciseType ? @"1" : @"0"),
@"exerciseName":(myExercise.exerciseName ? myExercise.exerciseName : @"0"),
@"exerciseAuthorID":(myUser.nickname ? myUser.nickname : @"0"),
@"exerciseDescription":(myExercise.exerciseDescription ? myExercise.exerciseDescription : @"0"),
@"exerciseYoutube":(myExercise.exerciseYoutube ? myExercise.exerciseYoutube : @"0"),
@"exerciseID":(myExercise.exerciseWebID ? myExercise.exerciseWebID : @"0"),
@"exercisePicture":(myExercise.exercisePic ? myExercise.exercisePic : @"0"),
@"exerciseDescriptionPic1":(myExercise.exerciseDesPic1 ? myExercise.exerciseDesPic1 : @"0"),
@"exercisePictureThumb":(myExercise.exercisePictureThumb ? myExercise.exercisePictureThumb : @"0")
}
}
};
NSLog(@"%@",params);
NSURL *url = [[NSURL alloc]initWithString:@"http://192.168.1.64/"];
AFHTTPClient *httpClient = [[AFHTTPClient alloc]initWithBaseURL:url];
NSURLRequest *request = [httpClient multipartFormRequestWithMethod:@"POST" path:@"igym/bootstrap.php" parameters:params constructingBodyWithBlock:^(id<AFMultipartFormData> formData)
{
/*
if(myExercise.exercisePictureThumb){
[formData appendPartWithFileData:exercisePictureThumb name:@"asd" fileName:myExercise.exercisePictureThumb mimeType:@"image/png"];
}
if(myExercise.exerciseDesPic1){
[formData appendPartWithFileData:exerciseDesPic1 name:@"asd" fileName:myExercise.exerciseDesPic1 mimeType:@"image/png"];
}
if(myExercise.exercisePic){
[formData appendPartWithFileData:exercisePic name:@"asd" fileName:myExercise.exercisePic mimeType:@"image/png"];
}
*/
}];
AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request
success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON){
NSLog(@"Inside the success block %@",JSON);
}
failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON){
NSLog(@"json text is: %@", JSON);
NSLog(@"Request failed with error: %@, %@", error, error.userInfo);
}];
[operation start];
}
答案 0 :(得分:0)
更新:this accepted pull request似乎可以解决您的问题。更新AFNetworking,并完成构造函数块。
您需要在构造函数块中放入一些代码;它看来是你的评论。
AFNetworking GitHub网站上有一个open issue related to this(已经存在了大约一个月)。已经应用了一些补丁但看起来没有100%解决。您可能希望确保使用最新版本的AFNetworking。