iPhone + Drupal + JSON RPC Server problem

左心房为你撑大大i 提交于 2019-12-03 04:01:23

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);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!