I'm having a problem migrating code from an android app to swift code.
This code is responsible for authenticating the user and password of an application.
I can not do swift 2 on xcode 7 for iOS 9.
Follow the code in java below:
@Override
protected Boolean doInBackground(Void... params) {
ArrayList<NameValuePair> postParameters;
postParameters = new ArrayList<>();
postParameters.add(new BasicNameValuePair("login", mUser));
postParameters.add(new BasicNameValuePair("password", mPassword));
HttpClient httpclient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(sUrl);
HttpResponse httpResponse;
try {
String base64 = Base64.encodeToString((mUser + ":" + mPassword).getBytes(),
Base64.NO_WRAP);
httpPost.addHeader("Authorization", "Basic " + base64);
httpPost.setEntity(new UrlEncodedFormEntity(postParameters));
httpResponse = httpclient.execute(httpPost);
} catch (IOException e) {
Log.e(TAG, "Error on request login", e);
return false;
}
int responseCode = httpResponse.getStatusLine().getStatusCode();
return responseCode == 200;
}