Ios 获取帖子内容类型错误
每次运行代码时,我都会遇到这个错误Ios 获取帖子内容类型错误,ios,json,swift,alamofire,stripe-payments,Ios,Json,Swift,Alamofire,Stripe Payments,每次运行代码时,我都会遇到这个错误 SUCCESS: { error = { message = "Invalid request (check that your POST content type is application/x-www-form-urlencoded). If you have any questions, we can help at https://support.stripe.com/."; type = "invalid_request_e
SUCCESS: {
error = {
message = "Invalid request (check that your POST content type is application/x-www-form-urlencoded). If you have any questions, we can help at https://support.stripe.com/.";
type = "invalid_request_error";
};
}
我正在使用Alamofire来完成这项工作,下面是我编写的代码
func alamoTest(){
let headers: HTTPHeaders = [
"Authorization":"Bearer test_keyxxxxx"]
let url = "https://api.stripe.com/v1/accounts"
let params = ["managed":"true","country":"us"]
Alamofire.request(url, method: .post, parameters: params, encoding: JSONEncoding.default, headers: headers).responseJSON {(response) in
print("this is what comes out", response)
if let data = response.data {
let json = String(data: data, encoding: String.Encoding.utf8)
print("Response:\(json)")
}
}
}
在文档中,我读到这是一个GET请求,而不是对该端点的POST请求
顺便说一句:您为什么不尝试使用stripe SDK:谢谢您的回复!是的,我尝试了stripe SDK,但我希望能够保存用户输入的信用卡,所以我的想法是为他们创建一个stripe帐户,然后保存他们的信用卡。你真的试图仿冒一张信用卡,用户只希望与stripe共享而不希望与你共享吗?这是因为你使用的是JSON。您需要将请求的
内容类型
-标题设置为application/x-www-form-urlencoded
。基本上,这意味着您的数据blob不会作为JSON发送到Stripe,它们需要作为查询字符串发送到Stripe。
curl https://api.stripe.com/v1/accounts \
-u {PLATFORM_SECRET_KEY}: \
-d country=US \
-d managed=true