我尝试使用名称和密码进行登录并将其传递给Url,但我的连接失败并给我这个错误。我做错了什么?
连接失败!错误 - 不支持的网址proyecto.lavidapirata.es/main/validate_credentials /
这是我的方法:
-(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;
}
这是我的控制台:
2011-05-26 11:50:32.856 PruebaPush [764:207] - [NSCFString setLength:]:无法识别的选择器发送到实例0x4bac460 2011-05-26 11:50:32.861 PruebaPush [764:207] *由于未捕获的异常'NSInvalidArgumentException'终止应用程序,原因:' - [NSCFString setLength:]:无法识别的选择器发送到实例0x4bac460' * 在第一次投掷时调用堆栈: ( 0 CoreFoundation 0x00dcb5a9 exceptionPreprocess + 185 1 libobjc.A.dylib 0x00f1f313 objc_exception_throw + 44 2 CoreFoundation 0x00dcd0bb - [NSObject(NSObject)doesNotRecognizeSelector:] + 187 3 CoreFoundation 0x00d3c966 __ 转发 + 966 4 CoreFoundation 0x00d3c522 _CF_forwarding_prep_0 + 50 5 PruebaPush 0x00003320 - [FirstViewController连接:didReceiveResponse:] + 111 6基础0x0005c3d0 - [NSURLConnection(NSURLConnectionReallyInternal)sendDidReceiveResponse:] + 143 7基金会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 ) 抛出'NSException'实例后调用终止
答案 0 :(得分:0)
错误表示正在使用的网址错误。请检查您的网址