0
I’m having a problem migrating a code from an android app to a code in Swift.
This code is responsible for authenticating the user and password of an application.
I am unable to run Swift 2 on Xcode 7 for iOS 9.
Follow the java code 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;
}
What have you tried so far? If you already have some code, even if it is not working, post so it is easier to help you.
– Otávio
I made a new post with the code I’m trying
– Fernando Júnior