Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7854899
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T20:13:32+00:00 2026-06-02T20:13:32+00:00

I am using ASIHTTPRequest framework for making network calls in my iOS applications. But

  • 0

I am using ASIHTTPRequest framework for making network calls in my iOS applications. But I don’t want to use it directly in all the controllers in my application. So I thought of writing a layer around ASIHTTPRequest. My code use this layer to use ASIHTTPRequest. The benefit wil be in future I should be able to replace this framework with some other framework and my code will be unchanged just the layer would change. I want to know what should be the strategy to do so. Should I subclass my class from ASIHTTPRequest class, or implement my own class. What should be the method I should consider implementing.

Currently I am implementing it like this.
My wrapper is

MyRequestHandler.h : NSObject       
@property ASIHTTPRequest *asiHttpReq;    

-(void) sendAsyncGetRequest
{
    self.asiRequest = [ASIHTTPRequest requestWithURL:self.url];
    if(self.tag != 0){
        self.asiRequest.tag = self.tag;
    }
    [self.asiRequest setDelegate:self];
    [self.asiRequest startAsynchronous];        
}

- (void)requestFinished:(ASIHTTPRequest *)request{
     MyResponseObj *respone = <From request obj>
     if([delegate respondsToSelector:@selector(requestFinished:)]){
            [delegate performSelector:@selector(requestFinished:) withObject:response];
        }
 }

And in my viewcontroller I would do this:

MyViewController.h : UIViewContoller
@property MyRequestHandler *reqHandler;

-(void) fireRequest
{
NSString* requestUrl = <create URL>;
if(requestUrl){

    // [self showLoadingIndicatorView];

    // Proceed for request.
    NSURL *url = [NSURL URLWithString:requestUrl];
    reqHandler = [MyRequestHandler requestWithURL:url];
    reqHandler.tag = 1000;
    [reqHandler setDelegate:self];
    [reqHandler sendAsyncGetRequest];
}
}

- (void)requestFinished:(MyResponse*) responseData{
        // Do Your parsing n all here.
}

- (void)requestFailed:(MyResponse*) responseData{
        // Handle the error here.
}

Is this the right way to do it. The problem here is as I have created property of myrequesthandler in viewcontroller I can only make one request at a time, and loosing the capability of ASIHTTPRequest of making multiple request simultaneously.

Can you suggest me how to approach problems like this.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T20:13:34+00:00Added an answer on June 2, 2026 at 8:13 pm

    This is what I’m using:

    #import "ASIFormDataRequest.h"
    
    @interface RequestPerformer : NSObject {
        id localCopy; // to avoid exec_bad_access with arc
        ASIHTTPRequest *getRequest;
        ASIFormDataRequest *postRequest;
    }
    
    @property (nonatomic, retain) id delegate;
    @property (nonatomic, readwrite) SEL callback;
    @property (nonatomic, readwrite) SEL errorCallback;
    
    - (void)performGetRequestWithString:(NSString *)string stringDictionary:(NSDictionary *)stringDictionary delegate:(id)requestDelegate requestSelector:(SEL)requestSelector errorSelector:(SEL)errorSelector;
    - (void)performPostRequestWithString:(NSString *)string stringDictionary:(NSDictionary *)stringDictionary dataDictionary:(NSDictionary *)dataDictionary delegate:(id)requestDelegate requestSelector:(SEL)requestSelector errorSelector:(SEL)errorSelector;
    
    @end
    

    //

    #import "RequestPerformer.h"
    #import "ASIHTTPRequest.h"
    #import "ASIFormDataRequest.h"
    
    @implementation RequestPerformer
    
    @synthesize delegate;
    @synthesize callback, errorCallback;
    
    - (void)performGetRequestWithString:(NSString *)string stringDictionary:(NSDictionary *)stringDictionary delegate:(id)requestDelegate requestSelector:(SEL)requestSelector errorSelector:(SEL)errorSelector {
    
        localCopy = self;
    
        self.delegate = requestDelegate;
        self.callback = requestSelector;
        self.errorCallback = errorSelector;
    
        NSMutableString *requestStringData = [[NSMutableString alloc] init];
        if (stringDictionary)
            for (NSString *key in [stringDictionary allKeys])
                [requestStringData appendFormat:@"%@=%@&", key, [stringDictionary objectForKey:key]];
        NSString *resultString = [requestStringData substringToIndex:[requestStringData length]-1];
    
        getRequest = [[ASIFormDataRequest alloc] initWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@?%@", string, [resultString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]]];
        [getRequest setDelegate:self];
        [getRequest setRequestMethod:@"GET"];
    
        //NSLog(@"request url = %@", [getRequest.url absoluteString]);
        [getRequest startAsynchronous];
    }
    
    - (void)performPostRequestWithString:(NSString *)string stringDictionary:(NSDictionary *)stringDictionary dataDictionary:(NSDictionary *)dataDictionary delegate:(id)requestDelegate requestSelector:(SEL)requestSelector errorSelector:(SEL)errorSelector {
    
        localCopy = self;
    
        self.delegate = requestDelegate;
        self.callback = requestSelector;
        self.errorCallback = errorSelector;
    
        NSURL *url = [NSURL URLWithString:string];
    
        postRequest = [[ASIFormDataRequest alloc] initWithURL:url];
        [postRequest setDelegate:self];
        [postRequest setRequestMethod:@"POST"];
    
        if (stringDictionary)
            for (NSString *key in [stringDictionary allKeys])
                [postRequest setPostValue:[stringDictionary objectForKey:key] forKey:key];
    
        if (dataDictionary)
            for (NSString *key in [dataDictionary allKeys])
                [postRequest setData:[dataDictionary objectForKey:key] forKey:key];
    
        //NSLog(@"request url = %@", [postRequest.url absoluteString]);
        [postRequest startAsynchronous];
    }
    
    #pragma mark - ASIHTTPRequest Delegate Implementation
    
    - (void)requestFinished:(ASIHTTPRequest *)crequest {
        NSString *status = [crequest responseString];
    
        if (self.delegate && self.callback) {
            if([self.delegate respondsToSelector:self.callback])
                [self.delegate performSelectorOnMainThread:self.callback withObject:status waitUntilDone:YES];
            else
                NSLog(@"No response from delegate");
        }
        localCopy = nil;
    }
    - (void)requestFailed:(ASIHTTPRequest *)crequest {
        if (self.delegate && self.errorCallback) {
            if([self.delegate respondsToSelector:self.errorCallback])
                [self.delegate performSelectorOnMainThread:self.errorCallback withObject:crequest.error waitUntilDone:YES];
            else
                NSLog(@"No response from delegate");
        }
        localCopy = nil;
    }
    
    @end
    

    To use it, just import RequestPerformer.h in your UIViewController and do smth like:

    [requestManager performGetRequestWithString:tempString stringDictionary:stringDictionary dataDictionary:dataDictionary delegate:self requestSelector:@selector(requestSucceeded:) errorSelector:@selector(requestFailed:)];
    

    Parameters:

    • (NSString *)string – url string, where to post your request;
    • (NSDictionary *)stringDictionary – dictionary, which contains all the
      text information (such as name, id etc.);
    • (NSDictionary *)dataDictionary – dictionary, which contains all data information (such as photos, files, etc.);
    • (id)requestDelegate – delegate to perform selectors below;
    • (SEL)requestSelector – selector, which will be executed while successfully request;
    • (SEL)errorSelector – selector, which will be executed, while error occurred.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using ASIHTTPRequest library and I want to be sure if I use it
I'm using ASIHTTPRequest in my iOS project. i would like to see all the
I am sending http request to my server using ASIHTTPRequest library but I don't
I am using ASIHTTPRequest 1.6.2 lib for all http transactions in IPhone. But i
We must support some old code that runs using ASIHTTPRequest, but we want the
i am using ASIHTTPRequest in my iOS APP. i am doing like this :
I'm successfully using yajl-objc along with ASIHTTPRequest in an iPhone project that does network
I am using ASIHTTPRequest, and i have to make use of the POST method
I am using ASIHTTPRequest for downloading file from server but its giving error Failed
I´ve just started using ASIHTTPRequest for iOs and I have a small issue with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.