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];
}];
后端自定义的状态码吧?######后段么有任何设置,后段的timeout设置的为0 也就是说只有关闭浏览器才会出来超时,我IOS 移动端么有用浏览器 直接用的AFNetwork 方法 请求的。
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。