0

Hi i am beginner in iOS and in my project there is facility for users "ForGotPassword" request using NSURLConnection post request

For this i have written some code but that is not working and showing exception like

"This class is not key value coding-compliant for the key MedicaidId.'"

what did i do here wrong please help me

my code:-

- (void)viewDidLoad {

 [super viewDidLoad];

NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"my-url"]];

    [request setHTTPMethod:@"POST"];

    [request setValue:self.MedicalIdTxt.text forKey:@"MedicaidId"];

    [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];

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

    if (theConnection) {
        NSLog(@"connected");

        receivedData=[[NSMutableData alloc]init];
    }
    else {

        NSLog(@"not connected");
    }
}

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
    [receivedData setLength:0];
}

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
    [receivedData appendData:data];
    NSString* responseString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
    NSLog(@"response: %@",responseString);
}

- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
    NSLog(@"Succeeded! Received %lu data",(unsigned long)[receivedData length]);

    NSString* responseString = [[NSString alloc] initWithData:receivedData encoding:NSUTF8StringEncoding];

    NSLog(@"response: %@",responseString);

    NSError *myError = nil;

    NSDictionary *res = [NSJSONSerialization JSONObjectWithData:receivedData options:NSJSONReadingMutableLeaves error:&myError];

    NSLog(@"final result is %@",res);
}
Max
  • 5,380
  • 6
  • 42
  • 66
  • check this http://stackoverflow.com/questions/3088059/what-does-this-mean-nsunknownkeyexception-reason-this-class-is-not-key – Max Oct 06 '15 at 14:49
  • `[request setValue:self.MedicalIdTxt.text forKey:@"MedicaidId"];` What are you trying to do exactly with that? That's the line which is causing issue because `NSMutableRequest` doesn't know "MedicaidId" as one of its property. – Larme Oct 06 '15 at 14:51
  • i want to post that "MedicaidId" to server –  Oct 06 '15 at 14:52
  • You honestly should be using NSURLSession FYI – TheCodingArt Oct 06 '15 at 14:53
  • can you please explain through program i am begginer in ios –  Oct 06 '15 at 14:54
  • set debug and check this line [request setValue:self.MedicalIdTxt.text forKey:@"MedicaidId"]; if you can't run this app. Because app crashes as soon as you run your app. then I am sure,in .xib file find out a varible "**MedicaidId**" and delete the connection. – Jamil Oct 06 '15 at 15:07
  • see my comment . i hope your problem will solve. – Jamil Oct 06 '15 at 15:14

0 Answers0