ios - 获取 POST 内容类型错误

标签 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_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 请求

https://stripe.com/docs/connect/managed-accounts

curl https://api.stripe.com/v1/accounts \
  -u {PLATFORM_SECRET_KEY}: \
  -d country=US \
  -d managed=true

顺便说一句:你为​​什么不尝试使用 stripe SDK:https://stripe.com/docs/mobile/ios

关于ios - 获取 POST 内容类型错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42959859/

相关文章:

javascript - 为网络应用程序存储长格式文本

java - 使用 JSON Parsing with volley 更新 ListView 的最佳方法

macos - NS窗口闪烁

ios - 适用于 iPad 的交互式 3D 模型

IOS:关于将 subview (UIView)添加到 UIScrollView 实例中的问题

Java Jackson 解析动态 JSON 对象

swift - 使用 UIScrollview 和 UICollectionView 滚动整个屏幕

ios - 如何使用 CGAffine 正确缩小 UIProgressView?

ios - React Native 23.1 意外 token (14 :6)

ios - 我如何在 ARSKView 中创建暂停菜单?