如何访问“http://webservices.ns.nl/ns-api-stations”使用 ASIHTTPRequest

发布于 2024-12-13 20:01:39 字数 1592 浏览 0 评论 0原文

我正在尝试访问 XML http://webservices.ns.nl/ns-api-stations< /a> 使用 ASIHTTPRequest。但我现在用的似乎不起作用。它说主机无法访问。所以我认为 ASIHTTPRequest 部分出了问题?

-(void)fetchStationData {
//Method for the fetching of the data

//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"];
     ASIHTTPRequest *requestaccount = [ASIHTTPRequest requestWithURL:url];
     [requestaccount setUsername:@"user"];
     [requestaccount setPassword:@"password"];
    //The XML elements to fetch
    NSArray *elements = [[NSArray alloc] initWithObjects:@"name",nil];
    //The actual fetchin
    [parser fetchStationItemsForUrl:url forElements:elements];

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

    //Clean up
    [elements release]; 

}else{

    //Internet is down  :( 
    //Offline artikelen inladen

    //Dit uitvoeren op de main que
    dispatch_async(dispatch_get_main_queue(), ^ {

        UIAlertView *Notpermitted = [[UIAlertView alloc] initWithTitle:@"Alert" message:@"Er is geen verbinding mogelijk met de Mezz. Offline artikelen zijn ingeladen." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];

        [Notpermitted show];
        [Notpermitted release];

    });

}

}

I am trying to access the XML http://webservices.ns.nl/ns-api-stations using ASIHTTPRequest. But what I am using now doesn't seem to work. It says the host is not reachable. So I assume it is going wrong at the ASIHTTPRequest part?

-(void)fetchStationData {
//Method for the fetching of the data

//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"];
     ASIHTTPRequest *requestaccount = [ASIHTTPRequest requestWithURL:url];
     [requestaccount setUsername:@"user"];
     [requestaccount setPassword:@"password"];
    //The XML elements to fetch
    NSArray *elements = [[NSArray alloc] initWithObjects:@"name",nil];
    //The actual fetchin
    [parser fetchStationItemsForUrl:url forElements:elements];

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

    //Clean up
    [elements release]; 

}else{

    //Internet is down  :( 
    //Offline artikelen inladen

    //Dit uitvoeren op de main que
    dispatch_async(dispatch_get_main_queue(), ^ {

        UIAlertView *Notpermitted = [[UIAlertView alloc] initWithTitle:@"Alert" message:@"Er is geen verbinding mogelijk met de Mezz. Offline artikelen zijn ingeladen." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];

        [Notpermitted show];
        [Notpermitted release];

    });

}

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

瀟灑尐姊 2024-12-20 20:01:39

使用ASIFormDataRequest

NSURL *url = [NSURL URLWithString:@"http://webservices.ns.nl/ns-api-stations"];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
[request addPostValue:@"accountname" forKey:@"username"];
[request addPostValue:@"password" forKey:@"password"];

[request setCompletionBlock:^ {
  // do something when request succeeds and credentials are ok, e.g. redirect user to the home page
}];

[request setFailedBlock:^ {
  // notify user that request failed
}];

[request startAsynchronous];

Use ASIFormDataRequest.

NSURL *url = [NSURL URLWithString:@"http://webservices.ns.nl/ns-api-stations"];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
[request addPostValue:@"accountname" forKey:@"username"];
[request addPostValue:@"password" forKey:@"password"];

[request setCompletionBlock:^ {
  // do something when request succeeds and credentials are ok, e.g. redirect user to the home page
}];

[request setFailedBlock:^ {
  // notify user that request failed
}];

[request startAsynchronous];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文