post (rest)

 self.URLSession=[NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
    self.URLRequest=[NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://www.google.php"]];
    self.URLRequest.HTTPMethod=@"POST";
    
    NSMutableString *dataToServer=[NSMutableString stringWithFormat:@"funcName=%@&registeredEmail=%@&registeredPassword=%@",@"verifyLogin",self.userNameTF.text,self.passwordTF.text];
    NSData *dataToPassToServer=[dataToServer dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
    NSString *postLength=[NSString stringWithFormat:@"%lu",(unsigned long)[dataToPassToServer length]];
    [self.URLRequest setValue:postLength forHTTPHeaderField:@"Content-Length"];
    [self.URLRequest setValue:@"application/x-www-form-urlencoded;charset=utf-8" forHTTPHeaderField:@"Content-Type"];
    [self.URLRequest setHTTPBody:dataToPassToServer];
    

    self.dataTask=[self.URLSession dataTaskWithRequest:self.URLRequest completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error)
    {
        self.responseDictonary = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
        
        NSLog(@"%@",self.responseDictonary);
        

    }];
   
  
 [self.dataTask resume];
        }

   
Previous
Next Post »