gpt4 book ai didi

objective-c - 如何使用 ASIHTTPRequest 访问 "http://webservices.ns.nl/ns-api-stations"

转载 作者:行者123 更新时间:2023-11-28 23:11:50 25 4
gpt4 key购买 nike

我正在尝试访问 XML http://webservices.ns.nl/ns-api-stations使用 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];

});

}

}

最佳答案

使用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];

关于objective-c - 如何使用 ASIHTTPRequest 访问 "http://webservices.ns.nl/ns-api-stations",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8027613/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com