【问题标题】:Stripe Payment in IOS App With Error Invalid Request ErrorIOS 应用程序中的条带支付错误无效请求错误
【发布时间】:2014-10-18 01:13:28
【问题描述】:

我正在开发一个需要我使用 Stripe 创建和更新收件人的 iOS 应用。当我运行代码时,我从收到的数据中收到错误:“2014-08-24 17:28:42.962 myapp[1703:60b] data: { “错误”: { "type": "invalid_request_error", "message": "收到未知参数:sk_test_******:", “参数”:“sk_test_******:” } }"

如果有人可以帮助我或向我展示另一种方法来向 Stripe 发送请求以创建新收件人,我不确定为什么我会收到此错误。

NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"https://api.stripe.com/v1/recipients"]];

                             NSString *params = [NSString stringWithFormat:@"%@:&name=%@&type=individual&card=%@",StripeSecretKey,name,token.tokenId];
                             request.HTTPMethod = @"POST";
                             request.HTTPBody = [params dataUsingEncoding:NSUTF8StringEncoding];
                             [NSURLConnection sendAsynchronousRequest:request
                                           queue:[NSOperationQueue mainQueue]
                      completionHandler:^(NSURLResponse *response, NSData *data, NSError *error)
                              {
                                  if (error)
                                  {
                                      NSLog(@"ERROR: %@",error);
                                  }
                                  else
                                  {
                                      NSLog(@"data: %@", response);
                                      NSLog(@"data: %@", [[NSString alloc] initWithData:data encoding: NSUTF8StringEncoding]);
                                  }
                              }];

【问题讨论】:

    标签: ios objective-c xcode httprequest stripe-payments


    【解决方案1】:

    当您想将其设置为标头时,您将在请求正文中发送您的密钥。用这两个替换你的 params = 行:

    [request setValue:[@"Bearer " stringByAppendingString:StripeSecretKey] forHTTPHeaderField:@"Authorization"];
    NSString *params = [NSString stringWithFormat:@"name=%@&type=individual&card=%@",name,token.tokenId];
    

    【讨论】:

    • 感谢您的回复。进行更改后,我收到此错误:错误:错误域=NSURLErrorDomain 代码=-1012“操作无法完成。(NSURLErrorDomain 错误-1012。)”{NSErrorFailingURLKey=api.stripe.com/v1/recipients,NSErrorFailingURLStringKey=https://…,NSUnderlyingError=0x17efb6d0“的操作无法完成。(kCFErrorDomainCFNetwork 错误 -1012。)“} 我在网上看到该错误可能是由于我的 SK_KEY 造成的,但它是正确的。我试图在最后添加一个“:”,但它没有用。你知道我该如何解决这个问题吗?
    猜你喜欢
    • 2021-02-13
    • 2015-07-08
    • 2018-12-07
    • 2021-09-21
    • 2014-12-11
    • 1970-01-01
    • 1970-01-01
    • 2017-03-02
    • 2013-09-15
    相关资源
    最近更新 更多