【问题标题】:Connection failed! Error - unsupported URL连接失败!错误 - 不支持的 URL
【发布时间】:2011-05-25 22:05:29
【问题描述】:

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

连接失败!错误 - 不受支持的 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 异常预处理 + 185 1 libobjc.A.dylib 0x00f1f313 objc_exception_throw + 44 2核心基础0x00dcd0bb-[NSObject(NSObject)不识别选择器:]+187 3 CoreFoundation 0x00d3c966 __转发 + 966 4 核心基础 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 核心基础 0x00dac8ff CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 15 14 核心基础 0x00d0a88b __CFRunLoopDoSources0 + 571 15 核心基础 0x00d09d86 __CFRunLoopRun + 470 16 核心基础 0x00d09840 CFRunLoopRunSpecific + 208 17 核心基础 0x00d09761 CFRunLoopRunInMode + 97 18 图形服务 0x017221c4 GSEventRunModal + 217 19 图形服务 0x01722289 GSEventRun + 115 20 UIKit 0x002c9c93 UIApplicationMain + 1160 21 PruebaPush 0x00002778 主 + 102 22 PruebaPush 0x00002709 开始 + 53 ) 在抛出 'NSException' 的实例后调用终止

【问题讨论】:

  • 您确定这与您使用的代码相同吗?从您的错误来看,您似乎缺少前面的 http://。

标签: iphone xcode


【解决方案1】:

错误表示使用的url是错误的。检查你的url地址

【讨论】:

  • 该 URL 有效,现在我将其更改为 lavidapirata.es/main/validate_credentials/ 我想我必须在其中写下我的姓名和密码,但是当我这样做时,它会用 html 代码响应我,所以我不知道出了什么问题,我的问题是我必须在 web 服务代码中做一些特定的事情?
猜你喜欢
  • 1970-01-01
  • 2020-04-24
  • 2015-05-11
  • 1970-01-01
  • 2021-01-17
  • 1970-01-01
  • 2017-02-13
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多