本文介绍了使用AFNetworking 2 POST请求时的可可错误3840的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我每次调用此函数并返回Cocoa Error 3840。
我尝试调试并修复它,它在请求时出错而不是在解析结果时出错

I call this function and return Cocoa Error 3840 every time.I try to debug and fix it and it error when request rather than when parse the result

我发现失败时此错误会在请求时阻止。

I found this error in failure blocks when request.

Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be completed. (Cocoa error 3840.)" (JSON text did not start with array or object and option to allow fragments not set.) UserInfo=0x109230960 {NSDebugDescription=JSON text did not start with array or object and option to allow fragments not et.}
2013-11-01 12:09:30.925 MagicBox[87431:70b] The operation couldn’t be completed. (Cocoa error 3840.)

这是我的代码
先谢谢。

That's my code Thanks in Advance.

- (void)loginWithUserName:(NSString *)userName
             Password:(NSString *)password
           orFacebook:(NSString *)facebookID
    withResponseBlock:(ResponseBlock)responseBlock {

if (!userName && !facebookID) {
    NSError *error = [NSError errorWithDomain:@"Missing Parameters"
                                         code:400
                                     userInfo:@{ NSLocalizedDescriptionKey : @"Username or FacebookID is required"}];
    responseBlock(error, nil);
}

NSDictionary *params;

if (facebookID) {
    params = @{ @"fb_id": facebookID };
} else {
    params = @{ @"username": userName,
                @"password": password };
}

AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
NSString *loginURL = [self requestWithPath:@"/api/login"];
[manager POST:loginURL
   parameters:params
constructingBodyWithBlock:nil
      success:^(AFHTTPRequestOperation *operation, id responseObject) {
          if (responseBlock) {
              responseBlock(nil, responseObject);
          }
      }
      failure:^(AFHTTPRequestOperation *operation, NSError *error) {
          if (responseBlock) {
              responseBlock(error, nil);
          }
      }];
}


推荐答案

我通过添加以下内容解决了这个问题代码行

I solved it by adding following line of code

这篇关于使用AFNetworking 2 POST请求时的可可错误3840的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-12 23:16