A simple package of iOS crazy ASIHTTPRequest

Source: Internet
Author: User

A simple package of iOS crazy ASIHTTPRequest
WLHTTPClient.h
Wlwllisten
//
Created by long on 14-12-15.
Copyright (c) 2014 Wlong. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "ASIFormDataRequest.h"

@protocol wlhttpclientdelegate<nsobject>
@optional
@end

@interface Wlhttpclient:nsobject

@property (nonatomic,assign) id<wlhttpclientdelegate>delegate;

+ (wlhttpclient *) sharedclient;


-(void) Postinfowithdelegate: (id<wlhttpclientdelegate>) delegate
Withmethod: (NSString *) method
Withparams: (nsdictionary *) params
Withsuccuessmethod: (SEL) Successmethod
Withfailedmethod: (SEL) Failmethod;

@end


//
Wlhttpclient.m
Wlvkolisten
//
Created by long on 14-12-15.
Copyright (c) 2014 Wlong. All rights reserved.
//

#import "WLHTTPClient.h"

#define SUPPRESSPERFORMSELECTORLEAKWARNING (Stuff) \
do {\
_pragma ("clang diagnostic push") \
_pragma ("clang diagnostic ignored \"-warc-performselector-leaks\ "") \
Stuff; \
_pragma ("clang diagnostic pop") \
} while (0)


@implementation Wlhttpclient

+ (Wlhttpclient *) sharedclient
{
static wlhttpclient *_sharedclient = nil;
Static dispatch_once_t Oncetoken;
Dispatch_once (&oncetoken, ^{
_sharedclient = [[Wlhttpclient alloc]init];

});

return _sharedclient;

}

-(void) Postinfowithdelegate: (id<wlhttpclientdelegate>) delegate
Withmethod: (NSString *) method
Withparams: (nsdictionary *) params
Withsuccuessmethod: (SEL) Successmethod
Withfailedmethod: (SEL) Failmethod
{

NSString *urlstr = [NSString stringwithformat:@ "%@%@", Basehttpurl,method];

__weak asiformdatarequest *request = [asiformdatarequest requestwithurl:[nsurl urlwithstring:urlstr]];

[Request setrequestmethod:@ "POST"];

for (int i = 0; i < [params allkeys].count; i++) {
[Request Addpostvalue:params[[params Allkeys][i]] forkey:[params allkeys][i];
}

[Request setcompletionblock:^{

NSData *jsondata = Request.responsedata;

ID result = [nsjsonserialization jsonobjectwithdata:jsondata options:nsjsonreadingmutablecontainers Error:nil];

Suppressperformselectorleakwarning (
[Delegate Performselector:successmethod Withobject:result];
);

}];

[Request setfailedblock:^{

Suppressperformselectorleakwarning (
[Delegate Performselector:failmethod withobject:@ "Network connection failed, please check your network connection or retry! "];
);
}];

[Request startasynchronous];


}


@end


More iOS Madness: Http://blog.csdn.net/wanglongblog

A simple package of iOS crazy ASIHTTPRequest

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.