我正在尝试在swift中使用Plaid,但是他们似乎没有办法在swift中原生地发出API请求,但是他们确实有curl。我知道您可以在swift中发出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中。
谢谢
发布于 2021-02-02 10:53:25
这是一个非常具体的问题,在某种程度上,没有人能为你回答。您必须自己编写代码,以便在出现问题时能够理解和调试它。话虽如此,这里有一个关于如何发出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";
显然,您会希望使用plaid变量,而不是示例。但这应该会让你开始学习。
https://stackoverflow.com/questions/66002903
复制相似问题