2016-09-15 3 views
0

bonjour tout ce que je sais ce genre de question posée précédemment mais je n'ai pas obtenu de solution de leur part dans mon projet je travaille dans la vue de connexion quand je mets le code sur bouton de connexion Je reçois une erreurIOS: erreur kCFErrorDomainCFNetwork -1002. Error Domain = NSURLErrorDomain Code = -1002 "URL non supportée"

erreur: erreur de domaine = NSURLErrorDomain code = -1002 "URL non pris en charge" UserInfo = {0x7fb37b62c9a0 NSLocalizedDescription = URL non pris en charge, NSUnderlyingError = 0x7fb37b715a20 « L'opération n'a pas pu être terminée. (Erreur de kCFErrorDomainCFNetwork -1002.) "}

mais je suis en utilisant le même code pour la connexion que j'ai utilisé dans mes projets précédents et il fonctionne très bien, il

voici mon code:

-(IBAction)login:(id)sender 
{ 
    NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration]; 
    NSURLSession *session = [NSURLSession sessionWithConfiguration:configuration delegate:self delegateQueue:nil]; 
    NSURL *url = [NSURL URLWithString:@"http://eyeforweb.info.bh-in-15.webhostbox.net/myconnect/api.php?token={LS0tLS1CRUdJTiBQVUJMSUMgS0VZLS0tLS0KTUc4d0RRWUpLb1pJaHZjTkFRRUJCUUFEWGdBd1d3SlVBeWo0WE9JNjI4cnJRTG9YeEpXNG1zUWI1YmtvYk1hVQpzMnY1WjFKeXJDRWdpOVhoRzZlZk4rYTR0eGlMTVdaRXdNaS9uS1cyL1NCS2pCUnBYUzVGYUdiV0VLRG1WOXkvCkYrWHhsUXVoeER0MEV3YkRBZ01CQUFFPQotLS0tLUVORCBQVUJMSUMgS0VZLS0tLS0K}&method=user.getLogin"]; 
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url 
                  cachePolicy:NSURLRequestUseProtocolCachePolicy 
                 timeoutInterval:60.0]; 

    [request addValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"]; 
    [request addValue:@"*/*" forHTTPHeaderField:@"Accept"]; 
    [request setHTTPMethod:@"POST"]; 
    NSString *mapData = [NSString stringWithFormat:@"[email protected]&password=123456"];//,username.text, password.text]; 
    NSData *postData = [mapData dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES]; 
    [request setHTTPBody:postData]; 
    NSLog(@"map data is = %@",mapData); 
    NSURLSessionDataTask * postDataTask = [session dataTaskWithRequest:request completionHandler:^(NSData * data, NSURLResponse* response, NSError * error) { 

     if(error == nil) 
     { 
      NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error]; 
      NSString *text = [[NSString alloc] initWithData: data encoding: NSUTF8StringEncoding]; 
      NSLog(@"Data = %@",text); 
      NSDictionary *jsonDic = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error]; 
      NSLog(@"jsondic= %@",jsonDic); 

      NSDictionary *userDataDic = [jsonDic objectForKey:@"data"]; 
      NSLog(@"Dict is %@",userDataDic); 

S'il vous plaît aidez-moi à le résoudre, je vois déjà la même type de questions, mais n'a pas surmonté de cette question Toute aide est appréciée

+0

Abi votre URL est incorrect – user3182143

+0

mais donner une réponse correcte dans le client de repos avance – Abhi

+0

quand je lance votre code, il me donne nul – user3182143

Répondre

0

J'ai essayé votre code.Except votre url les autres lignes de code est correct.Si vous passez votre URL corrct, cela fonctionne parfaitement.

NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"http://eyeforweb.info.bh-in-15.webhostbox.net/myconnect/api.php"]]; //pass your url here 
[request setHTTPMethod:@"POST"]; 
//Passing The String to server 
NSString *strUserId = @"[email protected]"; 
NSString *strPassword = @"admin123"; 


NSString *userUpdate =[NSString stringWithFormat:@"login=%@&password=%@",strUserId,strPassword, nil]; 

//Check The Value what we passed 
NSLog(@"the data Details is %@", userUpdate); 


//Convert the String to Data 
NSData *data1 = [userUpdate dataUsingEncoding:NSUTF8StringEncoding]; 
NSLog(@"The postData is - %@",data1); 


//Apply the data to the body 
[request setHTTPBody:data1]; 

NSURLSession *session = [NSURLSession sharedSession]; 
NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) { 
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response; 
if(httpResponse.statusCode == 200) 
{ 
NSError *parseError = nil; 
NSDictionary *responseDictionary = [NSJSONSerialization JSONObjectWithData:data options:0 error:&parseError]; 
NSLog(@"The response is - %@",responseDictionary); 
NSInteger success = [[responseDictionary objectForKey:@"success"] integerValue]; 
if(success == 1) 
{ 
NSLog(@"Login SUCCESS"); 
} 
else 
{ 
NSLog(@"Login FAILURE"); 
} 
} 
else 
{ 
NSLog(@"Error"); 
} 
}]; 
[dataTask resume];