MKNetworkKit
MKNetworkKit copied to clipboard
How to send JSON body ?
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" ...
}
I added this line .. op.postDataEncoding = MKNKPostDataEncodingTypeJSON; you can close this issue
that's what i'm looking for thank you very much 给你点个赞