如何访问“http://webservices.ns.nl/ns-api-stations”使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用
ASIFormDataRequest
。Use
ASIFormDataRequest
.