user3745888
user3745888

Reputation: 6353

How to send any params in JSONHTTP with Objective c?

I need send a post json request to an url. This service need two identifiers, ow can I sent it with JSONHTTPClient??

With postman I write:

{
   "token" : "apitoken",
   "identifier" : 1
}

But with objective c code I dont know how to add this two elements into request:

 //add extra headers
 [[JSONHTTPClient requestHeaders] setValue:@"MySecret" forKey:@"AuthorizationToken"];

 //make post, get requests
 [JSONHTTPClient postJSONFromURLWithString:@"http://myd.com/api"
                               params:@{}
                           completion:^(id json, JSONModelError *err) {

                               //check err, process json ...

                           }];

Upvotes: 1

Views: 72

Answers (1)

ncke
ncke

Reputation: 1094

Populate the params dictionary.

//make post, get requests
[JSONHTTPClient postJSONFromURLWithString:@"http://myd.com/api"
                           params:@{ @"token": @"apitoken",
                                     @"identifier": @1 }
                       completion:^(id json, JSONModelError *err) {

                           //check err, process json ...

                       }];

See the JSONHTTPClient Class Reference:

postJSONFromURLWithString:params:completion:

params: a dictionary of key / value pairs to be send as variables to the request

Upvotes: 1

Related Questions