各种坑,有木有。。。

1.AFNetwork

        AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
        NSString *reqStr = [NSString stringWithFormat:@"%@%@.do",@"http://172.20.0.11:8080/quickLogin/quickApp/tom/",_contentStr];
        [manager GET:reqStr
          parameters:nil
             success:^(AFHTTPRequestOperation *operation, id responseObject) {
                 
                 float sta = [[responseObject objectForKey:@"status"] floatValue];
                 if (sta == 1) {
                     [self alShow:@"PC端成功登录"];
                 }else if (sta == 0){
                     [self alShow:@"PC端登录失败"];
                 }
                 
             } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
                 NSLog(@"Error:%@",error);
             }];

其实这个没什么问题,主要就是,你要让服务器端考虑周全,要不然你这里将会遇到一堆蛋疼的Bug。

{ status code: 200, headers {

    "Content-Length" = 12;

    "Content-Type" = "text/plain;charset=ISO-8859-1";

    Date = "Thu, 17 Apr 2014 09:38:46 GMT";

    Server = "Apache-Coyote/1.1";

} }, NSLocalizedDescription=Request failed: unacceptable content-type: text/plain}

这里一看就知道是服务器端格式问题,服务器端没有设置好,只是设置成了text/plain,假如非要你那里改也是可以的,加上这个:

manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/plain"];

但是你这样改了之后,成功后返回的responseObject解析要出问题了,所以还是服务器端统一做一下处理把!

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFData countByEnumeratingWithState:objects:count:]: unrecognized selector sent to instance 0x17d72560'

还有一些bug基本上,你直接copy错误,stackoverflow上就能找到答案了,我就不废话了。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 134,868评论 18 139
  • Spring Boot 参考指南 介绍 转载自:https://www.gitbook.com/book/qbgb...
    毛宇鹏阅读 46,937评论 6 342
  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 173,020评论 25 708
  • *面试心声:其实这些题本人都没怎么背,但是在上海 两周半 面了大约10家 收到差不多3个offer,总结起来就是把...
    Dove_iOS阅读 27,203评论 30 471
  • headsense 1.查看所有index: 2.查看索引的type、mapping: 3.查看某索引的某类型的数...
    ll0292阅读 2,565评论 2 3