ASIHTTPRequest for dummies [英] ASIHTTPRequest for dummies

查看:102
本文介绍了ASIHTTPRequest for dummies的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在ASIHTTPRequest中完成了DUMMY。我刚刚下载了库并将其添加到我的项目中,现在我正在尝试理解使用它的基础知识。我发现了一些非常好的例子 here

I'm COMPLETE DUMMY in ASIHTTPRequest. I have just downloaded the library and added it to my project and now i'm trying to understand basics of working with it. I've found some pretty good example here

这个小教程是关于将图像上传到服务器的。我试过它,事情似乎有效(但我对[request responseString]返回的NSString感到困惑,它返回了整个网页的HTML代码)但是我想知道如何下载图像(或任何上传的)服务器。搜索了一下后,我发现 这个 它没有给我任何答案,只有更多的问题,因为它对我来说还不太清楚。
让我来解决一下我的问题:

this little tutorial is about uploading images to a server. I tried it and things seem to work (but i'm confused with NSString returned by [request responseString], it returned HTML code of a whole web page ) but i would like to know how to download images (or anything uploaded) back from the server. After searching a bit i found this and it gave me no answers but more questions only, cause it's quite unclear for me. Let me enumurate my questions:

1)请您提供一小段代码,说明如何下载数据(无论哪种数据) :来自服务器的图像,字符串,数字等)?

1) Could you please provide me with a little piece of code showing how to download data (no matter what kind of data: images,strings,numbers etc) from a server?

2)我是否应该知道服务器端的php代码才能使用服务器?

2)Should i know php code of the server side in order to work with a server?

3)如果是 - 我怎么知道服务器端的PHP代码?

3)If yes - how do i know php code of the server side?

4)多么重要如果请求是通过php脚本或任何不同的方式处理的吗?

4)How important is it if a request is proccessed by a php script or by any different means?

5)responseString的作用是什么?它给我一个巨大的HTML代码是否可以?

5)What is the role of responseString? Is it ok that it returned me a huge HTML code?

6)主要问题。 ASIHTTPRequest有一个很好的教程吗?像ASIHTTPRequest for dummies之类的东西?我找到了官方文档 here ,但它解释了东西真的很糟糕,我只是找不到任何其他教程。

6)The main question. Is there a good tutorial for ASIHTTPRequest? Something like "ASIHTTPRequest for dummies"? I found official documentation here but it explains the stuff really poorly and i just can't find any other tutorials.

迫切需要任何帮助。

推荐答案


1)请您提供一小段代码,说明如何下载数据(无论哪种数据:图像,字符串,数字等)来自服务器?

1) Could you please provide me with a little piece of code showing how to download data (no matter what kind of data: images,strings,numbers etc) from a server?

在这里你可以找到一个非常基本的POST示例:

here you can find a very basic POST example:

NSURL *url = [NSURL URLWithString:@"http://localhost/webroot/index.php/test/signUp"];

ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
[request addPostValue:@"Raul" forKey:@"name"];
[request addPostValue:@"Hello World" forKey:@"message"];

[request setCompletionBlock:^{
    NSString *responseString = [request responseString];
    NSLog(@"Response: %@", responseString);
}];
[request setFailedBlock:^{
    NSError *error = [request error];
    NSLog(@"Error: %@", error.localizedDescription);
}];

[request startAsynchronous];

它使用了块,因此在一个函数中将所有东西很好地打包在一起而你不需要与代表和其他人打交道。 (来源

it uses blocks, so that wverything is nicely packed together in one function and you don't have to deal with delegates and the rest. (source)

如果您只想获取页面,可以使用:

If you just want to GET a page, you can use:

NSURL *url = [NSURL URLWithString:@"http://allseeing-i.com"];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request setCompletionBlock:^{
    NSString *responseString = [request responseString];
    NSLog(@"Response: %@", responseString);
}];
[request setFailedBlock:^{
    NSError *error = [request error];
    NSLog(@"Error: %@", error.localizedDescription);
}];

[request startAsynchronous];

[request startAsynchronous];


2)我是否应该知道服务器端的php代码才能使用服务器?

2)Should i know php code of the server side in order to work with a server?

绝对不是必要。


3)如果是 - 我怎么知道服务器端的php代码?

3)If yes - how do i know php code of the server side?

NA


4)如果请求被php处理,这有多重要脚本或通过任何不同的方式?

4)How important is it if a request is proccessed by a php script or by any different means?

服务器编写的语言也不相关。

the language the server is written in is not relevant either.


5)responseString的作用是什么?它是否可以返回给我一个巨大的HTML代码?

5)What is the role of responseString? Is it ok that it returned me a huge HTML code?

responseString包含服务器作为NSString发回给你的所有数据。它可能很大......

responseString contains all the data that the server sent back to you as an NSString. It can be huge...


6)主要问题。 ASIHTTPRequest有一个很好的教程吗?像ASIHTTPRequest for dummies之类的东西?我在这里找到官方文档点击但它解释的东西真的很差,我找不到任何其他教程。

6)The main question. Is there a good tutorial for ASIHTTPRequest? Something like "ASIHTTPRequest for dummies"? I found official documentation here click but it explains the stuff really poorly and i just can't find any other tutorials.

我不知道知道像你说的傻瓜教程;你应该尝试按照网站上的文档;它们可能看起来很复杂,但并非如此。

I don't know of a tutorial "for dummies" like you say; you should try and follow the docs on the site; they may appear complex, but are not really.

另一方面,你可能已经知道了: ASIHTTP的开发已经停止。如果你刚刚开始学习它,你最好考虑考虑另一种选择。查看链接页面了解一些替代方案。

On another note, you probably already know it: development of ASIHTTP has been ceased. If you are just starting learning about it, you might better think of considering an alternative. Look at the linked page for some alternatives.

这篇关于ASIHTTPRequest for dummies的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆