gpt4 book ai didi

iPhone + Drupal + JSON RPC 服务器问题

转载 作者:行者123 更新时间:2023-12-03 21:23:39 34 4
gpt4 key购买 nike

我不知道如何使用 Obj-C 发布 JSON RPC 请求。谁能帮我吗?

到目前为止我已经:

responseData = [[NSMutableData data] retain];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://*************/services/json-rpc"]];

NSString *jsonString = @"{\"jsonrpc\": \"2.0\",\"method\": \"node.get\", \"params\": { \"arg1\": 1 } ,\"id\": \"dsadasdas\"}";
NSData *jsonData = [jsonString dataUsingEncoding:NSUTF32BigEndianStringEncoding];

[ request setHTTPMethod: @"POST" ];
[ request setHTTPBody: jsonData ];
[ request setValue:@"application/json" forHTTPHeaderField:@"Content-> Type"];

[[NSURLConnection alloc] initWithRequest:request delegate:self];

我正在使用 drupal + services + Json 服务器和 JSON rpc 服务器。

似乎我在第一个方面获得了更好的结果,问题是构建我认为的帖子正文......

请帮助我。

最佳答案

这解决了它:

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);

关于iPhone + Drupal + JSON RPC 服务器问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2596324/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com