How to translate CURL command with token into Swif

2019-08-22 05:11发布

I have this CURL command from our custom REST API which comes without any other documentation except sample CURL calls.

As I need this in Swift, how can I start to get this translated and working in Swift?

I used SwiftyJSON so far (for playing around with other APIs), but I dont see how I can include the access token in there.

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' 

Response

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

Result in 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},...

1条回答
该账号已被封号
2楼-- · 2019-08-22 05:26

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.

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()
    }
查看更多
登录 后发表回答