2011-11-05 57 views
2

我想從此URL獲取數據:http://webservices.ns.nl/ns-api-stations。該URL需要登錄。如何把這個登錄信息放入我的代碼中?這段代碼是我現在使用的。從URL中獲取密碼數據

- (無效){fetchStationData // 法數據

//First lets check wheater there is an internet connection and if the host is reachable 
if(internetActive) { 

    //Internet is active 

    //Init the parser 
    parser = [[RSSParser alloc] init]; 

    //Set he parser context 
    parser.context = context; 

    //The array to het the data from 
    NSURL *url = [NSURL URLWithString:@"http://webservices.ns.nl/ns-api-stations"]; 

    //The XML elements to fetch 
    NSArray *elements = [[NSArray alloc] initWithObjects:@"naam",nil]; 

    //The actual fetchin 
    [parser fetchStationItemsForUrl:url forElements:elements]; 

    //Save the context ? 
    [context save:nil]; 

    //Clean up 
    [elements release]; 

} 

回答

0

您嘗試訪問並獲取一些數據的服務器的抓取是需要某種形式的認證,以允許它..因此,在嘗試發出獲取請求之前,您需要執行身份驗證。因此,您需要知道他們正在使用哪種身份驗證方法(例如摘要身份驗證),並且您還需要用戶名和密碼。

此外,您還需要使用HTTPRequest庫。我建議你使用ASIHTTPRequest,這很簡單..你也可以在從服務器發出請求之前用asihtttprequest庫執行身份驗證。

+0

添加框架後工作很好:CFNetwork,SystemConfiguration,MobileCoreServices和libz。謝謝。 – Dawid

0

您鏈接的網站受basic auth的保護。其中一個簡單的方法來傳遞認證信息將憑據追加到URL:

http://user:[email protected]/ns-api-stations 

注意,該網站未採用SSL技術保護的,因此所有的認證信息都將被明文傳遞。