xcode 连接失败!错误 - 不受支持的 URL

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6131551/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 21:07:20  来源:igfitidea点击:

Connection failed! Error - unsupported URL

iphonexcode

提问by Evan

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?

我正在尝试使用名称和密码登录并将其传递给 Url,但我的连接失败并出现此错误。我究竟做错了什么?

Connection failed! Error - unsupported URL proyecto.lavidapirata.es/main/validate_credentials/

连接失败!错误 - 不支持的 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'

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 0x00fthrow_bb1f301except 0x4bac460cb1f30c -[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(NSURL sendConnectionReallyReceiveternal)] + 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 0x00dac8ffCFRUNLOOP_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主+ 102 22 PruebaPush 0x00002709 start + 53 ) 在抛出“NSException”实例后终止调用

回答by Tendulkar

the error means the url which is using is wrong.Check your url address

该错误表示正在使用的 url 是错误的。检查您的 url 地址