如何将curl格子请求转换为swift



我试图在swift中使用Plaid API,但似乎他们没有办法在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中。

感谢

这是一个非常具体的问题,在某种程度上没有人能回答你。您必须自己编写代码,以便在出现问题时能够理解并调试它。话虽如此,这里有一个关于如何制作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变量而不是示例。但这应该是你开始学习的基础。

最新更新