url - How to convert my curl to Objective-C -
i working on objective-c language , need fire curl objective-c.
my curl is:
curl https://api.start.payfort.com/tokens/ \ -u test_open_k_91ffe6d8f9efe14fcc91: \ -d "number=4242424242424242" \ -d "exp_month=11" \ -d "exp_year=2016" \ -d "cvc=123" \ -d "name=sapana"
please me how convert url in objective-c , fire url.
i tried other way return response like:
{ error = { code = "not_found"; extras = { "request_id" = "f8e70bf6-9391-49b0-9403-06cc9485c021"; time = "2016-01-27t11:10:31z"; }; message = "not found"; type = processing; }; }
it's work me. swift
func cardsendtopayfort(number:string, exp_month:string, exp_year:string, cvc:string, name:string, completion: ((success: bool, json: nsdictionary?) -> void)) { let username = "test_open_k_91ffe6d8f9efe14fcc91" let password = "" let loginstring = nsstring(format: "%@:%@", username, password) let logindata: nsdata = loginstring.datausingencoding(nsutf8stringencoding)! let base64loginstring = logindata.base64encodedstringwithoptions(nsdatabase64encodingoptions.encoding64characterlinelength) let orderurl = nsurl(string: "https://api.start.payfort.com/tokens/") let request = nsmutableurlrequest(url: orderurl!) request.setvalue("basic \(base64loginstring)", forhttpheaderfield: "authorization") let poststring = "number=\(number)&exp_month=\(exp_month)&exp_year=\(exp_year)&cvc=\(cvc)&name=\(name)" //let poststring = "number=4242424242424242&exp_month=11&exp_year=2016&cvc=123&name=sapana" request.httpbody = poststring.datausingencoding(nsutf8stringencoding) request.httpmethod = "post" let session = nsurlsession.sharedsession() let task = session.datataskwithrequest(request) { (data, response, error) -> void in if let httpstatus = response as? nshttpurlresponse httpstatus.statuscode != 201 { print("statuscode should 201, \(httpstatus.statuscode)") print("response = \(response)") dispatch_async(dispatch_get_main_queue()){ completion(success: false, json: nil) } } else { let responsestring = string(data: data!, encoding: nsutf8stringencoding) let jsondata = responsestring?.datausingencoding(nsutf8stringencoding, allowlossyconversion: false) let json = try! nsjsonserialization.jsonobjectwithdata(jsondata!, options: nsjsonreadingoptions.mutablecontainers) as! nsdictionary dispatch_async(dispatch_get_main_queue()){ completion(success: true, json: json) } } } task.resume() }
Comments
Post a Comment