0
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"riderfinder.appspot.com/login"]];
    [request setHTTPMethod:@"POST"];
    [request setValue:@"text/plain" 
   forHTTPHeaderField:@"Content-type"];

    NSString *body = @"username=";
    [body stringByAppendingString:accountEntered];
    [body stringByAppendingString:@"&"];
    [body stringByAppendingString:@"password="];
    [body stringByAppendingString:passwordEntered];

    NSMutableData *data = [[NSMutableData data] initWithString:body];

    //Crashes everything with "SIGABRT" warning/error. Nothing else is said.
    [request setHTTPBody:data];

I would appreciate it if anyone has any idea what is going wrong. I narrowed it down to the last line causing the crash through Apple's debugger. Thank you very much!

2 Answers2

1

There are 2 errors:

  1. body is not appended, [body stringByAppendingString:accountEntered] should be body=[body stringByAppendingString:accountEntered]

  2. NSMutableData *data = [[NSMutableData data] initWithString:body]; is not correct used,you can use NSData *data=[body dataUsingEncoding:NSUTF8StringEncoding];

so i modified the code:

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"riderfinder.appspot.com/login"]];
[request setHTTPMethod:@"POST"];
[request setValue:@"text/plain" forHTTPHeaderField:@"Content-type"];

NSString *body = @"username=";
body=[body stringByAppendingString:accountEntered];
body=[body stringByAppendingString:@"&"];
body=[body stringByAppendingString:@"password="];
body=[body stringByAppendingString: passwordEntered];

//NSMutableData *data = [[NSMutableData data] initWithString:body];
NSData *data=[body dataUsingEncoding:NSUTF8StringEncoding];

[request setHTTPBody:data];
Mil0R3
  • 3,876
  • 4
  • 33
  • 61
  • @LearningPython really? it ran on my Mac without any problem. Have you set *accountEntered* and *passwordEntered* correctly? – Mil0R3 Sep 10 '12 at 04:01
0

First,you should make 'accountEntered' and 'passwordEntered' not nil. If you have done that,you should set breakpoint to know exactly which line crashes.Usually, "SIGABRT" error means you release more or unrecogized selector . The code on answer 1 is right.

Vic
  • 61
  • 1
  • 7