swift - NSURLSession returns data with bad access code -
this function returning nil value data variable reason , can't understand why. have searched through many posts , can't seem find difference. had working request using different data if curl responses identical. makes far line states:
if let jsondata = responsestring?.datausingencoding(nsutf8stringencoding) {
and never goes if because responsestring
value never set. changing implicit like
if let jsondata = responsestring!.datausingencoding(nsutf8stringencoding) {
returns bad access code.
func getdata(url: string, datatosend: string, username: string, password: string) { somevar = [myobjecttype]() let request = nsmutableurlrequest(url: nsurl(string: "%urltouse%")!) request.httpmethod = "post" let poststring = "%postdatahere%" request.httpbody = poststring.datausingencoding(nsutf8stringencoding) let task = nsurlsession.sharedsession().datataskwithrequest(request) { data, response, error in let responsestring = nsstring(data: data, encoding: nsutf8stringencoding) dump(responsestring) if let jsondata = responsestring?.datausingencoding(nsutf8stringencoding) { if var jsondict = nsjsonserialization.jsonobjectwithdata(jsondata, options: nil, error: nil) as? nsdictionary { if var jsoninfo = jsondict["data"] as? nsdictionary { if var jsoninfosub = jsoninfo["data"] as? [nsdictionary] { report in jsoninfosub { self.somevar.append(myobjecttype(json: report)) } } } } } } task.resume() }
all appreciated!
edit: additional information
this dump output other variables
dumping data
returns bad access code
response: - <nshttpurlresponse: 0x7fbc5aca7120> { url: ____ } { status code: 200, headers { connection = "keep-alive"; "content-length" = 428205; "content-type" = "text/html; charset=iso-8859-1"; date = "fri, 29 may 2015 17:11:04 gmt"; "keep-alive" = "timeout=3, max=100"; p3p = "cp=\"noi deva taia our bus uni sta\""; server = apache; "set-cookie" = "_____; expires=sat, 28-may-2016 17:11:04 gmt; httponly, _____=76b17d064b58c412d078b5430ca9367e; httponly"; "x-powered-by" = plesklin; "x-robots-tag" = "noindex, nofollow"; } } #0
error returns: - nil
Comments
Post a Comment