I´m trying to make a login with name and password and pass it to a Url, but my connection fail and give me this error. What am I doing wrong?
Connection failed! Error - unsupported URL proyecto.lavidapirata.es/main/validate_credentials/
This is my method:
-(IBAction)login:(id)sender{
NSString *uName = userName.text;
NSString *uPass = userPass.text;
if([userName.text isEqualToString:@""] || [userPass.text isEqualToString:@""])
{
greeting.text = @"Input Your Value";
//[userName resignFirstResponder];
//[userPass resignFirstResponder];
return;
}
NSString *post =
[[NSString alloc] initWithFormat:@"uname=%@&pwd=%@",uName,uPass];
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding
allowLossyConversion: YES];
NSString *postLength = [NSString stringWithFormat:@
"%d",[postData length]];
//Parte de la petición
NSURL *url =
[NSURL URLWithString:@"http://proyecto.lavidapirata.es"];
//proyecto.lavidapirata.es/main/validate_credentials
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
[theRequest setHTTPMethod:@"POST"];
[theRequest setValue:postLength forHTTPHeaderField:@"Content-Length"];
[theRequest setHTTPBody:postData];
NSURLConnection *theConnection = [[NSURLConnection alloc]
initWithRequest:theRequest delegate:self];
if(theConnection)
{
webData = [[NSMutableData data] retain];
}
else
{
}
//[userName resignFirstResponder];
//[userPass resignFirstResponder];
userName.text = nil;
userPass.text = nil;
}
that´s my console:
2011-05-26 11:50:32.856 PruebaPush[764:207] -[NSCFString setLength:]: unrecognized selector sent to instance 0x4bac460 2011-05-26 11:50:32.861 PruebaPush[764:207] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSCFString setLength:]: unrecognized selector sent to instance 0x4bac460' * Call stack at first throw: ( 0 CoreFoundation 0x00dcb5a9 exceptionPreprocess + 185 1 libobjc.A.dylib 0x00f1f313 objc_exception_throw + 44 2 CoreFoundation 0x00dcd0bb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187 3 CoreFoundation 0x00d3c966 __forwarding + 966 4 CoreFoundation 0x00d3c522 _CF_forwarding_prep_0 + 50 5 PruebaPush 0x00003320 -[FirstViewController connection:didReceiveResponse:] + 111 6 Foundation 0x0005c3d0 -[NSURLConnection(NSURLConnectionReallyInternal) sendDidReceiveResponse:] + 143 7 Foundation 0x0005c306 _NSURLConnectionDidReceiveResponse + 146 8 CFNetwork 0x013730cc _ZN19URLConnectionClient29_clientSendDidReceiveResponseEP14_CFURLResponsePNS_26ClientConnectionEventQueueE + 46 9 CFNetwork 0x0143f7ec _ZN19URLConnectionClient26ClientConnectionEventQueue33processAllEventsAndConsumePayloadEP20XConnectionEventInfoI12XClientEvent18XClientEventParamsEl + 560 10 CFNetwork 0x0143f9cf _ZN19URLConnectionClient26ClientConnectionEventQueue33processAllEventsAndConsumePayloadEP20XConnectionEventInfoI12XClientEvent18XClientEventParamsEl + 1043 11 CFNetwork 0x0136ac84 _ZN19URLConnectionClient13processEventsEv + 100 12 CFNetwork 0x0136aad3 _ZN17MultiplexerSource7performEv + 251 13 CoreFoundation 0x00dac8ff CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 15 14 CoreFoundation 0x00d0a88b __CFRunLoopDoSources0 + 571 15 CoreFoundation 0x00d09d86 __CFRunLoopRun + 470 16 CoreFoundation 0x00d09840 CFRunLoopRunSpecific + 208 17 CoreFoundation 0x00d09761 CFRunLoopRunInMode + 97 18 GraphicsServices 0x017221c4 GSEventRunModal + 217 19 GraphicsServices 0x01722289 GSEventRun + 115 20 UIKit 0x002c9c93 UIApplicationMain + 1160 21 PruebaPush 0x00002778 main + 102 22 PruebaPush 0x00002709 start + 53 ) terminate called after throwing an instance of 'NSException'