I don\'t have any idea how to post a JSON RPC request using Obj-C. Can anyone help me?
So far I have:
responseData = [[NSMutableData data] retain];
NSMut
This fixed it:
SBJSON *json = [SBJSON new];
json.humanReadable = YES;
NSString *service = @"node.get";
NSMutableDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:
@"1",@"nid",
nil];
//Pass it twice to escape quotes
NSString *jsonString = [NSString stringWithFormat:@"%@", [params JSONFragment], nil];
NSString *changeJSON = [NSString stringWithFormat:@"%@", [jsonString JSONFragment], nil];
NSLog(jsonString);
NSLog(changeJSON);
NSString *requestString = [NSString stringWithFormat:@"method=node.get&vid=1",service,changeJSON,nil];
NSLog(requestString);
NSData *requestData = [NSData dataWithBytes: [requestString UTF8String] length: [requestString length]];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL: [NSURL URLWithString: @"http://******************/services/json"]];
NSString *postLength = [NSString stringWithFormat:@"%d", [requestData length]];
[request setHTTPMethod: @"POST"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody: requestData];
//Data returned by WebService
NSData *returnData = [NSURLConnection sendSynchronousRequest: request returningResponse: nil error: nil ];
NSString *returnString = [[NSString alloc] initWithData:returnData encoding: NSUTF8StringEncoding];
NSLog(returnString);