使用OAuthConsumer将NSArray参数发送到RESTful Web服务

时间:2011-10-19 20:03:09

标签: iphone arrays rest post request

我正在使用OAuthConsumer框架/帮助程序类来与RESTful Web服务进行通信。我解决了OAuth舞蹈:-)但我有一些需要数组参数的函数。

我正在设置参数

OARequestParameter *p0 = [[OARequestParameter alloc] initWithName:@"key"
                                                                value:@"value"];
NSArray *params = [NSArray arrayWithObjects:p0, nil];

OAMutableURLRequest *request = [[OAMutableURLRequest alloc] initWithURL:url
                                                               consumer:    [MyOAUthAppDelegate sharedAppDelegate].consumer
                                                                  token:[MyOAUthAppDelegate sharedAppDelegate].accessToken   // we don't have a Token yet
                                                                  realm:nil   // our service provider doesn't specify a realm
                                                      signatureProvider:[[OAHMAC_SHA1SignatureProvider alloc] init]]; // use the default method, HMAC-SHA1

[request setHTTPMethod:@"POST"];

OADataFetcher *fetcher = [[OADataFetcher alloc] init]; //

[fetcher fetchDataWithRequest:request
                     delegate:self
            didFinishSelector:@selector(requestTokenTicket:didFinishRESTWithData:)
              didFailSelector:@selector(requestTokenTicket:didFailTESTWithError:)];

但WS返回“只接受数组”。

我的规格如下:

REST (POST parameters)

params[xxx]= int
params[yyy]= int

我认为在PHP或Javascript中这很容易,但我不知道如何从iPhone请求发送Array参数,特别是使用OAuthConsumer对象:S

1 个答案:

答案 0 :(得分:0)

我得到了这样的参数:

OARequestParameter *p0 = [[OARequestParameter alloc] initWithName:@"function"
                                                                value:functionName];

OARequestParameter *p1 = [[OARequestParameter alloc] initWithName:@"params[c_id]" 
                                                                value:@"2"]; 
OARequestParameter *p2 = [[OARequestParameter alloc] initWithName:@"params[a_id]" 
                                                                value:@"1"]; 
NSArray *params = [NSArray arrayWithObjects:p0, p1, p2, nil];
[request setParameters:params];