Something does not work out for me to encode one variable, tell me how to do it.
public class LoginPage extends Activity { public static final String Login = "login"; public static final String Password = "password"; protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.efrgtaw); inal EditText loginIn = (EditText) findViewById(R.id.editText2); final EditText password = (EditText) findViewById(R.id.editText3); Button butlogin = (Button) findViewById(R.id.button1); butlogin.setOnClickListener(new Button.OnClickListener() { @Override public void onClick(View v) { Toast.makeText(getBaseContext(),"Please wait, connecting to server.", Toast.LENGTH_LONG).show(); try { String loginValue = URLEncoder.encode(loginIn.getText().toString(), "UTF-8"); String passwordStr = URLEncoder.encode(password.getText().toString(), "UTF-8"); HttpClient Client = new DefaultHttpClient(); String URL = "http://" + accountValue + ".megaplan.ru/BumsCommonApiV01/User/authorize.api/"+ loginValue + passwordStr + ""; Log.i("httpget", URL); try { String SetServerString = ""; HttpGet httpget = new HttpGet(URL); ResponseHandler<String> responseHandler = new BasicResponseHandler(); SetServerString = Client.execute(httpget,responseHandler); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally {} } catch (UnsupportedEncodingException e) { e.printStackTrace(); } finally {}}});}}
I want to pass the password in the form of md5. Just password, login not to touch.
This option did not want to work:
MessageDigest digest = java.security.MessageDigest.getInstance("MD5"); digest.update(Password.getBytes()); byte messageDigest[] = digest.digest(); StringBuffer MD5Hash = new StringBuffer(); for (int i = 0; i < messageDigest.length; i++){ String h = Integer.toHexString(0xFF & messageDigest[i]); while (h.length() < 2) h = "0" + h; MD5Hash.append(h);}
passwordStr
fromEditText
, and send it, in its pure form. - falstaf