I am trying to write a code that will grab some information provided by my server (remote), for example request a url that will return data that will be represented in the application after parsing it.
我正在编写一个代码,它将获取我的服务器(远程)提供的一些信息,例如请求一个url,该url将返回解析后在应用程序中表示的数据。
I've been trying since 2 days now I googled it i found some incomplete solution but nothing really worked out for me
我已经试了两天了,我在谷歌上搜了一下我找到了一些不完整的解决方案,但是没有什么对我有用
I am really noob in Xcode and Objective-C
我是Xcode和Objective-C的新手
Thanks
谢谢
1 个解决方案
#1
9
Click for the URL-Loading documentation provided by Apple. Especially Using NSURLConnection
looks interesting for you.
点击苹果提供的url加载文档。尤其是使用NSURLConnection看起来很有趣。
Edit: Another very good and easy-to-use Framework for this task is ASIHTTP: Click
编辑:另一个非常好的、易于使用的框架是ASIHTTP:单击
The easiest way:
最简单的方法:
- (void)grabURL
{
NSURL *url = [NSURL URLWithString:@"http://allseeing-i.com"];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request startSynchronous];
NSError *error = [request error];
if (!error) {
NSString *response = [request responseString];
}
}
Asynchronous loading is only slightly more complex:
异步加载只是稍微复杂一点:
- (void)grabURLInBackground
{
NSURL *url = [NSURL URLWithString:@"http://allseeing-i.com"];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request setDelegate:self];
[request startAsynchronous];
}
- (void)requestFinished:(ASIHTTPRequest *)request
{
// Use when fetching text data
NSString *responseString = [request responseString];
// Use when fetching binary data
NSData *responseData = [request responseData];
}
- (void)requestFailed:(ASIHTTPRequest *)request
{
NSError *error = [request error];
}
#1
9
Click for the URL-Loading documentation provided by Apple. Especially Using NSURLConnection
looks interesting for you.
点击苹果提供的url加载文档。尤其是使用NSURLConnection看起来很有趣。
Edit: Another very good and easy-to-use Framework for this task is ASIHTTP: Click
编辑:另一个非常好的、易于使用的框架是ASIHTTP:单击
The easiest way:
最简单的方法:
- (void)grabURL
{
NSURL *url = [NSURL URLWithString:@"http://allseeing-i.com"];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request startSynchronous];
NSError *error = [request error];
if (!error) {
NSString *response = [request responseString];
}
}
Asynchronous loading is only slightly more complex:
异步加载只是稍微复杂一点:
- (void)grabURLInBackground
{
NSURL *url = [NSURL URLWithString:@"http://allseeing-i.com"];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request setDelegate:self];
[request startAsynchronous];
}
- (void)requestFinished:(ASIHTTPRequest *)request
{
// Use when fetching text data
NSString *responseString = [request responseString];
// Use when fetching binary data
NSData *responseData = [request responseData];
}
- (void)requestFailed:(ASIHTTPRequest *)request
{
NSError *error = [request error];
}