MKNetworkKit icon indicating copy to clipboard operation
MKNetworkKit copied to clipboard

How to send JSON body ?

Open FilipLukac opened this issue 10 years ago • 2 comments

Hello Im trying to send JSON body via MKNetworkKit

    NSDictionary *finalJSON = @{@"company_id": self.token, // Authorization Token
                            @"type":event, // Event name
                            @"customer_ids": self.customer, // Customer ids specified in initialize
                            @"project_id": self.projectId, // project id if defined, otherwise null
                            @"properties":properties == nil ? @{} : properties}; // properties


MKNetworkOperation *op = [_engine operationWithPath:@"/crm/events" params:finalJSON httpMethod:@"POST"];
[op addCompletionHandler:
 ^(MKNetworkOperation *operation)
 {
     NSLog(@" Operation succeds: %@", [operation responseJSON]);
 }
 errorHandler:^(MKNetworkOperation *errorOperation, NSError *error)
 {
     NSLog(@" Errors occured: %@", error);
 }];

[_engine enqueueOperation:op];

it gives me curl -X POST -H 'Content-Type: application/x-www-form-urlencoded; charset=utf-8,application/json' -H 'Accept: application/json' 'http://api.7segments.com/crm/events' -d 'type=novyEventik' -d 'customer_ids={ registered = 1234; }' -d 'project_id=' -d 'company_id=7fa0a2c4-fead-11e3-b648-4061862b98a0' -d 'properties={ size = 43; }'

What should I do ? I want to send http request with json body like

{ company_id:"123", customer_ids:"123" ...

}

FilipLukac avatar Jul 11 '14 15:07 FilipLukac

I added this line .. op.postDataEncoding = MKNKPostDataEncodingTypeJSON; you can close this issue

FilipLukac avatar Jul 11 '14 18:07 FilipLukac

that's what i'm looking for thank you very much 给你点个赞

zhanyue4 avatar Jun 26 '15 08:06 zhanyue4