开发者社区> 问答> 正文

IOS 开发 HTTPS URL请求返回直接是-1012,求帮助? 400 报错

IOS 开发 HTTPS URL请求返回直接是-1012,求帮助? 400 报错

用一个定时器10秒循环请求一个方法,此方法里面用AFNetwork 进行了网络请求,请求一个URL,成功后可以获取到返回json,status code = 200 ,每隔16分钟左右 总会有一次失败,不知道是什么原因,以下是打印出来的错误:

Domain=NSURLErrorDomain Code=-1012 "(null)" UserInfo={NSErrorFailingURLKey=https://10.0.13.195/jumpvpn/pda_conn_hold.php?android_client=ture&enevs=login&inputname=test1&inputpsw=1&login=1, NSErrorFailingURLStringKey=https://10.0.13.195/jumpvpn/pda_conn_hold.php?android_client=ture&enevs=login&inputname=test1&inputpsw=1&login=1}

定时器10秒后请求就会成功,在请求失败的上一次请求中respone对象中如下:

<NSHTTPURLResponse: 0x7fc459c764e0> { URL: https://10.0.13.195/jumpvpn/pda_conn_hold.php?android_client=ture&enevs=login&inputname=test1&inputpsw=1&login=1 } { status code: 200, headers {

    "Cache-Control" = "no-store, no-cache, must-revalidate, post-check=0, pre-check=0";

    Connection = close;

    "Content-Length" = 41;

    "Content-Type" = "text/html";

    Date = "Fri, 13 May 2016 07:11:14 GMT";

    Expires = "Mon, 26 Jul 1997 05:00:00 GMT";

    "Last-Modified" = "Fri, 13 May 2016 07:11:14 GMT";

    Pragma = "no-cache";

    Server = Apache;

} }

其中Connection = close ,下次请求就会失败没有响应码,正常应该是

PHPSESSID=c968bf47a5f4c07dac04984f14b4d16d; alreadyLogin=1; auth_type=0; clientip=10.0.13.32; password=3368714a327a5474356d7951; user_rand_id=c968bf47a5f4c07dac04984f14b4d16d; username=test1

2016-05-13 15:14:19.860 loginIn[3693:1123694] <NSHTTPURLResponse: 0x7fc459c889d0> { URL: https://10.0.13.195/jumpvpn/pda_conn_hold.php?android_client=ture&enevs=login&inputname=test1&inputpsw=1&login=1 } { status code: 200, headers {

    "Cache-Control" = "no-store, no-cache, must-revalidate, post-check=0, pre-check=0";

    Connection = "Keep-Alive";

    "Content-Length" = 41;

    "Content-Type" = "text/html";

    Date = "Fri, 13 May 2016 07:11:25 GMT";

    Expires = "Mon, 26 Jul 1997 05:00:00 GMT";

    "Keep-Alive" = "timeout=15, max=98";

    "Last-Modified" = "Fri, 13 May 2016 07:11:25 GMT";

    Pragma = "no-cache";

    Server = Apache;

} }

哪位大神帮忙看看 小弟代码如下:

 AFHTTPRequestOperationManager *getManger = [AFHTTPRequestOperationManager manager];

    getManger.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];

    NSString * str = [NSString stringWithFormat:@"https://%@/jumpvpn/pda_conn_hold.php?android_client=ture",_serverView.valueField.text];

    AFSecurityPolicy *policy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeCertificate];

    policy.allowInvalidCertificates = YES;

    policy.validatesDomainName = NO;

    getManger.securityPolicy = policy;

    [getManger GET:str parameters:_params success:^(AFHTTPRequestOperation *operation, id responseObject) {

        NSLog(@"33");

        NSArray *cookies = [[NSHTTPCookieStorage sharedHTTPCookieStorage]cookiesForURL:[NSURL URLWithString:_url]];

        NSDictionary *cookieDict = [NSHTTPCookie requestHeaderFieldsWithCookies:cookies];

        NSLog(@"#####%@",cookieDict[@"Cookie"]);

        NSLog(@"%@",operation.response);

        if ([responseObject[@"hold_state"] intValue] == 1) {

            if ([responseObject isKindOfClass:[NSDictionary class]]) {

                NSDictionary *dict = (NSDictionary *)responseObject;

                NSArray *arr = [dict objectForKey:@"notice"];

                if (arr.count != 0) {

                    for (NSInteger i = 0; i < arr.count; i++) {

                        NSDictionary *dict = [arr objectAtIndex:i];

                        self.messageStr = [dict objectForKey:@"msg"];

                        self.pridStr = [dict objectForKey:@"prid"];

                        [self.msgArr addObject:_messageStr];

                        NSLog(@"%@",self.msgArr);

                        [VPNStatus shareInstance].contextStr = _messageStr;

                        [VPNStatus shareInstance].contextStr1 = _pridStr;

                        _messageStr = nil;

                    }

                }

                if (_msgArr != nil) {

                    self.array = [NSMutableArray arrayWithArray:_msgArr];

                    //NSLog(@"%@",_array);

                }

                [VPNStatus shareInstance].contextArr = _array;

                //NSLog(@"%@",_array);

            }

        }else{

            NSLog(@"22222");

            [self timerStop];

            [[NSNotificationCenter defaultCenter]postNotificationName:@"dianji" object:@"0"];

        }

    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {

        NSLog(@"-----------------------");

        NSLog(@"++++%@",error);

        [_connectTimer invalidate];

        [self loginConnect];

    }];


展开
收起
爱吃鱼的程序员 2020-06-01 14:37:42 753 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

    后端自定义的状态码吧?######后段么有任何设置,后段的timeout设置的为0 也就是说只有关闭浏览器才会出来超时,我IOS 移动端么有用浏览器 直接用的AFNetwork 方法 请求的。

    2020-06-01 14:37:44
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
手淘iOS性能优化探索 立即下载
From Java/Android to Swift iOS 立即下载
深入剖析iOS性能优化 立即下载