我正在开发一款iOS应用,要求我使用Stripe制作和更新收件人。当我运行代码时,我从收到的数据中收到错误:“2014-08-24 17:28:42.962 myapp [1703:60b]数据:{ “错误”:{ “type”:“invalid_request_error”, “message”:“收到未知参数:sk_test_ ****** :”, “param”:“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]);
}
}];
答案 0 :(得分:0)
当您要将其设置为标题时,您将在您的请求正文中发送您的密钥。用这两个代替params =
行:
[request setValue:[@"Bearer " stringByAppendingString:StripeSecretKey] forHTTPHeaderField:@"Authorization"];
NSString *params = [NSString stringWithFormat:@"name=%@&type=individual&card=%@",name,token.tokenId];