【问题标题】:Sending NSArray parameter to a RESTful webservice using OAuthConsumer使用 OAuthConsumer 将 NSArray 参数发送到 RESTful Web 服务
【发布时间】:2011-10-19 20:03:08
【问题描述】:

我正在使用 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 请求中发送数组参数,特别是使用 OAuthConsumer 对象:S

【问题讨论】:

    标签: iphone arrays rest post request


    【解决方案1】:

    我得到了它添加如下参数:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-02-04
      • 2014-03-23
      • 2014-07-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多