【问题标题】:How to convert a curl Plaid request to swift如何将 curl Plaid 请求转换为 swift
【发布时间】:2021-05-06 05:33:33
【问题描述】:

我试图在 swift 中使用 Plaid API,但似乎他们无法在 swift 中原生地发出 API 请求,但他们确实有 curl。我知道您可以快速发出 curl API 请求。

文档在 curl 中显示此 API 请求

curl -X POST https://sandbox.plaid.com/link/token/create -H 'Content-Type: application/json' -d '{
  "client_id": "CLIENT_ID",
  "secret": "SECRET",
  "user": {    "client_user_id": "unique-per-user",
  },
  "client_name": "Plaid App",
  "products": ["auth"],
  "country_codes": ["GB"],
  "language": "en",
  "webhook": "https://sample-web-hook.com",
  "account_filters": {
      "depository": {
          "account_subtypes": ["checking"]
      }
  }
}'

我如何将此 curl 请求转换为 swift - 特别是在 swiftUI 中。

谢谢

【问题讨论】:

    标签: ios swift api curl plaid


    【解决方案1】:

    这是一个非常具体的问题,在某种程度上没有人可以为您回答。您必须自己编写代码,以便在出现问题时能够理解和调试它。话虽如此,这里有一个关于如何发出 http post 请求的非常好的教程:

    https://www.appsdeveloperblog.com/http-post-request-example-in-swift/

    相关部分的开头如下:

    // Prepare URL 
    let url = URL(string: "https://jsonplaceholder.typicode.com/todos")
    guard let requestUrl = url else { fatalError() }
    // Prepare URL Request Object
    var request = URLRequest(url: requestUrl)
    request.httpMethod = "POST"
    
    // HTTP Request Parameters which will be sent in HTTP Request Body 
    let postString = "userId=300&title=My urgent task&completed=false";
    

    显然,您将希望使用格子变量而不是示例。但这应该可以帮助您入门。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-04-14
      • 1970-01-01
      • 2020-02-26
      • 2019-06-28
      • 2018-01-30
      • 2023-02-14
      • 2020-01-26
      • 2019-08-17
      相关资源
      最近更新 更多