2013-03-02 39 views
0

我認爲我的問題是像一個described here,但我不明白的答案。網址下載手動,但沒有與NSURLRequest

我的應用需要用戶輸入包含.pbn文件的網站的URL。但是,手動起作用的相同URL在我的應用程序的TextField中輸入時不起作用。在我的示例中,self.urlNameInput.text的情況爲http://www.atlantaduplicatebridgeclub.com/scorepost/2013/01/20130126ana.pbn,並且URL無法識別。

NSURLRequest *theRequest=[NSURLRequest requestWithURL:[NSURL URLWithString:self.urlNameInput.text] cachePolicy:NSURLRequestUseProtocolCachePolicy 
               timeoutInterval:60.0]; 

根據我是包含還是排除'http://',我得到以下錯誤消息。

連接失敗!錯誤 - 找不到具有指定主機名的服務器。 http://www.atlantaduplicatebridgeclub.com/scorepost/2013/01/20130126ana.pbn

連接失敗!錯誤 - 不支持的URL www.atlantaduplicatebridgeclub.com/scorepost/2013/01/20130126ana.pbn

回答

1

這似乎只是正常工作:

NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.atlantaduplicatebridgeclub.com/scorepost/2013/01/20130126ana.pbn"]]; 
[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) { 
    NSString *results = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; 
    NSLog(@"Results:%@", results); 
}]; 
+0

是的,在我有我成功使用下面的文本字段,也,但現在我遇到了TextField條目的問題。 'NSURLRequest * theRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:@「http://www.atlantaduplicatebridgeclub.com/scorepost/2013/01/20130126ana.pbn」] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];' – zerowords 2013-03-02 00:24:17

+0

謝謝。我有下載工作,但我有一個相關的問題。現在可以刪除以下委託方法:connection:didReceiveResponse:,connection:didReceiveData :, connection:didFailWithError:and connectionDidFinishLoading:因爲您正在使用其他路由?或者我可以以某種方式將您的方法與這些委託方法掛鉤? – zerowords 2013-03-02 18:35:45

+0

[這回答了我關於委託方法的問題](http://stackoverflow.com/questions/15181633/)。 – zerowords 2013-03-03 11:56:19