ASIHTTPRequest for dummies

前端 未结 1 508
傲寒
傲寒 2021-02-09 23:34

I\'m a 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 s

1条回答
  •  感情败类
    2021-02-10 00:14

    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?

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

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

    absolutely not necessary.

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

    N.A.

    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)What is the role of responseString? Is it ok that it returned me a huge HTML code?

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

    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.

    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.

    0 讨论(0)
提交回复
热议问题