如何将带有令牌的CURL命令转换为Swift? [英] How to translate CURL command with token into Swift?
问题描述
我从我们的自定义REST API中获得了这个CURL命令,除了示例CURL调用之外,它没有任何其他文档.
I have this CURL command from our custom REST API which comes without any other documentation except sample CURL calls.
在Swift中需要此功能时,如何开始在Swift中进行翻译和工作?
As I need this in Swift, how can I start to get this translated and working in Swift?
到目前为止,我已经使用SwiftyJSON(用于与其他API一起使用),但是我看不到如何在其中包含访问令牌.
I used SwiftyJSON so far (for playing around with other APIs), but I dont see how I can include the access token in there.
使用CURL进行示例通话
Sample call with CURL
curl -k -i -H "Accept: application/jsorization: Bearer
fbqgk5um9bei9newmitcjk8zqw12zw7b9" -X GET
'https://x43.herokuapp.com/x43/api/v1/sch?$aca=N'
响应
HTTP/1.1 200 OK
Server: Cowboy
Connection: keep-alive
X-Powered-By: Express
Content-Type: application/json; charset=utf-8
Date: Wed, 13 Jul 2016 15:05:28 GMT
Transfer-Encoding: chunked
Via: 1.1 vegur
JSON结果
{"result":[{"sco_id":2,"sco_type":"LS","name":"Phoenix
English","city":"Perth","cou_id":"AU","environment":"R","image":"-
","rating":0},{"sco_id":3,"sco_type":"LS","name":"Milner
college","city":"Perth ","cou_id":"AU","environment":"L","image":"-
","rating":0},...
推荐答案
这就是您要寻找的.我可以看到您是新手,因此,如果您可以花一些时间来了解iOS App开发的基础知识,那将是非常不错的.另外,我建议您发布带有一些代码段的问题,并进行了尝试.
This is what you are looking for. I can see that you are beginner, so it would be really great, if you can spend some time to go though the basics of iOS App Development. Also, I recommend you to post question with some snippet in it, which you tried out.
开始使用NSURLSession
,它将帮助您进行联网.
Get start with NSURLSession
, which will help you with Networking.
func apiRequest() {
let request = NSMutableURLRequest(URL: NSURL(string: "https://x43.herokuapp.com/x43/api/v1/sch?$aca=N")!)
let session = NSURLSession.sharedSession()
request.HTTPMethod = "GET"
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
request.setValue("fbqgk5um9bei9newmitcjk8zqw12zw7b9", forHTTPHeaderField: "Bearer")
let task = session.dataTaskWithRequest(request, completionHandler: { data, response, error in
})
task.resume()
}
这篇关于如何将带有令牌的CURL命令转换为Swift?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!