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 9018075
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T04:25:47+00:00 2026-06-16T04:25:47+00:00

in my app, I’m currently sending http requests from each viewcontroller. However, currently I’m

  • 0

in my app, I’m currently sending http requests from each viewcontroller. However, currently I’m implementing one class, that is supposed to have method for sending requests.

My requests vary in number of parameters. For example, to get list of things for tableview I need to put category, subcategory, filter and 5 more parameters into request.

This is what my request looks like now:

    NSMutableURLRequest *request = [[NSMutableURLRequest alloc]init];
         [request setValue:verifString forHTTPHeaderField:@"Authorization"]; 
         [request setURL:[NSURL URLWithString:@"http://myweb.com/api/things/list"]];
         [request setHTTPMethod:@"POST"];
         [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];

         NSMutableString *bodyparams = [NSMutableString stringWithFormat:@"sort=popularity"];
         [bodyparams appendFormat:@"&filter=%@",active];
         [bodyparams appendFormat:@"&category=%@",useful];
         NSData *myRequestData = [NSData dataWithBytes:[bodyparams UTF8String] length:[bodyparams length]];
[request setHTTPBody:myRequestData]

My first idea was to create method, that accepts all of these parameters, and those, which are not needed would be nil, then I would test which are nil and those which are not nil would be appended to parameter string (ms).

This is however pretty inefficient.
Later on I was thinking about passing some dictionary with stored values for a parameter. Something like array list with nameValuePair that’s used in android’s java.

I’m not sure, how would I get keys and objects from my dictionary

    -(NSDictionary *)sendRequest:(NSString *)funcName paramList:(NSDictionary *)params 
{
  // now I need to add parameters from NSDict params somehow
  // ?? confused here :)   
}
  • 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-16T04:25:48+00:00Added an answer on June 16, 2026 at 4:25 am

    You could construct your params string from a dictionary with something like this:

    /* Suppose that we got a dictionary with 
       param/value pairs */
    NSDictionary *params = @{
        @"sort":@"something",
        @"filter":@"aFilter",
        @"category":@"aCategory"
    };
    
    /* We iterate the dictionary now
       and append each pair to an array
       formatted like <KEY>=<VALUE> */      
    NSMutableArray *pairs = [[NSMutableArray alloc] initWithCapacity:0];
    for (NSString *key in params) {
        [pairs addObject:[NSString stringWithFormat:@"%@=%@", key, params[key]]];
    }
    /* We finally join the pairs of our array
       using the '&' */
    NSString *requestParams = [pairs componentsJoinedByString:@"&"];
    

    If you log the requestParams string you will get:

    filter=aFilter&category=aCategory&sort=something

    PS I totally agree with @rckoenes that AFNetworking is the best solution for this kind of operations.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

app link: http://itunes.apple.com/en/app/quick-tweet/id505987287?mt=12 How can i make something like that circle? is that a
My app runs fine on my machine (of course/famous last words). However, when deploying
app/models/zombie.rb class Zombie < ActiveRecord::Base attr_accessible :name validates :name, presence: true end spec/models/zombie_spec.rb require
My app's requirement is that it needs to take a picture and then divide
App Engine recently announced support for Cross Group (XG) transactions ; one would expect
My app reads an (html) file from my website, and I would like to
@app.route(/<requested_username>/<requested_team>, methods=['GET', 'POST']) ^How do I make this so that no matter what is
app.rb: require 'sinatra' class MyApp < Sinatra::Application enable :sessions if session[:user_id].nil? then erb :login
app.use(express.compiler({ src: __dirname + '/public', enable: ['less'] })); That's the line in my app.js
App having screen1, screen2, screen3 , screen4 user can go to screen3 from remaining

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.