首页 文章

IOS App中的连接问题

提问于
浏览
1

enter image description here
. 这是PLIST

NSString *post = [NSString stringWithFormat:@"email=%@&password=%@ & user_type=%@",_emailID.text,_password.text, user_type];
    NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
    NSString *postLength = [NSString stringWithFormat:@"%lu", (unsigned long)[postData length]];
    NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
    [request setURL:[NSURL URLWithString:@"my url"]];
    [request setHTTPMethod:@"POST"];
    [request setValue:postLength forHTTPHeaderField:@"Content-Length"];
    [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
    [request setHTTPBody:postData];

    NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:request delegate:self];

    if(conn) {
        NSLog(@"Connection Successful");
    } else {
        NSLog(@"Connection could not be made");
    }

}

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData*)data{
    [self.receivedData appendData:data];

}

- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error{
    NSLog(@"%@" , error);

}

- (void)connectionDidFinishLoading:(NSURLConnection *)connection{

    NSLog(@"Connected %@",connection); 
}

我在登录表单中使用此代码从电子邮件和密码字段POST数据 . 我正面临一个错误,没有得到任何回应 . 错误是:

2017-05-01 10:58:06.236 PK.Estate [13412:4023436] App Transport Security已阻止明文HTTP(http://)资源加载,因为它不安全 . 可以通过应用程序的Info.plist文件配置临时例外 . 2017-05-01 10:58:06.397 PK.Estate [13412:4022282]错误Domain = NSURLErrorDomain Code = -1022“无法加载资源,因为App Transport Security策略要求使用安全连接 . ” UserInfo = {NSUnderlyingError = 0x608000253260 {Error Domain = kCFErrorDomainCFNetwork Code = -1022“无法加载资源,因为App Transport Security策略要求使用安全连接 . ” UserInfo = {NSErrorFailingURLStringKey = url,NSLocalizedDescription =无法加载资源,因为App Transport Security策略需要使用安全连接 . ,NSErrorFailingURLKey = url}},NSErrorFailingURLStringKey = url,NSErrorFailingURLKey = url,NSLocalizedDescription =资源无法加载因为App Transport Security策略需要使用安全连接而被加载 . }

1 回答

  • 0

    我认为您在网址中使用http . 如果您正在使用此更改plist
    enter image description here

相关问题