Synchronous asynchronous request under IOS afnetworking

Source: Internet
Author: User


Blocking

-(User *) Finduser: (NSNumber *) UserID

{

NSString *url = [NSString stringwithformat:@ "%@/s/account/find-user/", Serverbaseurl];

Nsmutabledictionary *requestparms = [[Nsmutabledictionary alloc] init];

[Requestparms setobject:userid forkey:@ "UserID"];

Afjsonrequestserializer *requestserializer = [Afjsonrequestserializer serializer];

Nsmutableurlrequest *request = [Requestserializer requestwithmethod:@ "POST" Urlstring:url parameters:requestParms Error:nil];

Afhttprequestoperation *requestoperation = [[Afhttprequestoperation alloc] initwithrequest:request];

Afhttpresponseserializer *responseserializer = [Afjsonresponseserializer serializer];

[Requestoperation Setresponseserializer:responseserializer];

[Requestoperation start];

[Requestoperation waituntilfinished];

Nsdictionary *userinfo = [[requestoperation responseobject] objectforkey:@ "user"];

if (userInfo! = nil) {

Here the results are processed

return xxxx

}

return nil;

}

Asynchronous

NSString *url = [NSString stringwithformat:@ "%@/s/account/signin/", Serverbaseurl];

Nsmutabledictionary *requestparms = [[Nsmutabledictionary alloc] init];

Setting parameters

[Requestparms setobject:loginname forkey:@ "LoginName"];

[Httpmanager Post:url Parameters:requestparms

success:^ (afhttprequestoperation *operation, id responseobject) {

Success

} failure:^ (Afhttprequestoperation *operation, Nserror *error) {

Failed

}];


This article is from the "zhuoking" blog, make sure to keep this source http://9951038.blog.51cto.com/9941038/1772532

Synchronous asynchronous request under IOS afnetworking

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.