swift - Why is the base 64 encoding not working? -
i trying post username , password php script, works fine when not encoded, having trouble encoding on ios end. when print crypt <64584e6c 636d3568 6257566b 59585268 50556377 4e444134 4d546335 4a6e4268 63334e33 62334a6b 5a474630 59543172 6448526e 4e6a5935 4d673d3d>
, based on tutorials should getting string along lines of bxkgcgxhbmkgdgv4da==
var bodydata = "usernamedata=\(self.username.text!)&passworddata=\(self.password.text!)" request.httpmethod = "post" let encodestring = (bodydata.datausingencoding(nsutf8stringencoding)!); let crypt = encodestring.base64encodeddatawithoptions(nsdatabase64encodingoptions(rawvalue: 0)) request.httpbody = crypt print(crypt)
- i wouldn't recommend using
encodestring
variable name type nsdata (not string). - the function
base64encodeddatawithoptions
returns nsdata. if want stringbxkgcgxhbmkgdgv4da==
, can usebase64encodedstringwithoptions
.
Comments
Post a Comment