ios - Swift: Adding Headers to my REST POST Request -
i still learning swift , trying make post request web service via new ios app written in swift.
i need know how add 2 headers existing code. adding parameters correctly?
what have far:
let myurl = nsurl(string: "https://my-mobile-service.azure-mobile.net/api/login"); let request = nsmutableurlrequest(url:myurl!); request.httpmethod = "post"; // compose query string let poststring = "email=myemail@website.com&password=123"; request.httpbody = poststring.datausingencoding(nsutf8stringencoding); let task = nsurlsession.sharedsession().datataskwithrequest(request) { data, response, error in if error != nil { print("error=\(error)") return } print("response = \(response)") } task.resume()
here headers need add request:
x-zumo-application: 45634243542434
accept: application/json
how attach these headers request?
if use alamofire, should work, eases things choose or post
var pars2 : dictionary<string,string> = ["api_key":"value"] alamofire.request(.post, "someurlstring" ,parameters: pars2).responsejson() { (request, response, data, error) in if(data != nil) { self.countryidarray.removeall(keepcapacity: false) var status = data!["status"]!! as! string } }
Comments
Post a Comment