Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- protected String doInBackground(String... params) {
- String type = params[0];
- String login_url = "https://www.example.center/api/login";
- String login2 = "http://www.example2.win/index.php?action=login";
- if (type.equals("login")) {
- try {
- String email = params[1];
- String password = params[2];
- URL url = new URL(login_url);
- URL url2 = new URL(login2);
- final String COOKIES_HEADER = "Set-Cookie";
- HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
- HttpURLConnection httpURLConnection2 = (HttpURLConnection) url2.openConnection();
- java.net.CookieManager msCookieManager = new java.net.CookieManager();
- httpURLConnection.setDoOutput(true);
- httpURLConnection.setDoInput(true);
- httpURLConnection2.setDoOutput(true);
- httpURLConnection2.setDoInput(true);
- OutputStream outputStream = httpURLConnection.getOutputStream();
- OutputStream outputStream2 = httpURLConnection2.getOutputStream();
- BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(outputStream, "UTF-8"));
- String post_data = URLEncoder.encode("username", "UTF-8") + "=" + URLEncoder.encode(email, "UTF-8") + "&"
- + URLEncoder.encode("password", "UTF-8") + "=" + URLEncoder.encode(password, "UTF-8");
- BufferedWriter bufferedWriter2 = new BufferedWriter(new OutputStreamWriter(outputStream2, "UTF-8"));
- String post_data2 = URLEncoder.encode("myusername", "UTF-8") + "=" + URLEncoder.encode(email, "UTF-8") + "&"
- + URLEncoder.encode("mypassword", "UTF-8") + "=" + URLEncoder.encode(password, "UTF-8");
- bufferedWriter.write(post_data);
- bufferedWriter2.write(post_data2);
- bufferedWriter.flush();
- bufferedWriter.close();
- bufferedWriter2.flush();
- bufferedWriter2.close();
- outputStream.close();
- outputStream2.close();
- InputStream inputStream = httpURLConnection.getInputStream();
- InputStream inputStream2 = httpURLConnection2.getInputStream();
- BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream, "iso-8859-1"));
- BufferedReader bufferedReader2 = new BufferedReader(new InputStreamReader(inputStream2, "iso-8859-1"));
- Map<String, List<String>> headerFields = httpURLConnection2.getHeaderFields();
- List<String> cookiesHeader = headerFields.get(COOKIES_HEADER);
- if (cookiesHeader != null) {
- for ( String cookie : cookiesHeader) {
- msCookieManager.getCookieStore().add(null, HttpCookie.parse(cookie).get(0));
- cookies = cookie;
- }
- }
- while ((line = bufferedReader.readLine()) != null) {
- result += line;
- }
- bufferedReader.close();
- bufferedReader2.close();
- inputStream.close();
- inputStream2.close();
- httpURLConnection.disconnect();
- httpURLConnection2.disconnect();
- JSONObject obj= null;
- try {
- obj = new JSONObject(result);
- String status=obj.getString("status");
- JSONObject data_obj=obj.getJSONObject("data");
- win_user=data_obj.getString("id");
- name=data_obj.getString("name");
- logo=data_obj.getString("logo");
- return win_user;
- } catch (JSONException e) {
- e.printStackTrace();
- }
- return result;
- } catch (MalformedURLException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();}
- }
- return null;
- }
- @Override
- protected void onPreExecute() {
- alertDialog = new AlertDialog.Builder(context).create();
- alertDialog.setTitle("Login Status");
- }
- @Override
- protected void onPostExecute(String result) {
- if (result == null ) {
- Toast pass = Toast.makeText(context, "Email or Password is not match!", Toast.LENGTH_SHORT);
- pass.show();
- }
- else
- {
- context.startActivity( new Intent(context,Main.class));
- Main.JSON_STRING = result;
- Main.name = name;
- Main.logo = logo;
- Main.win_user = win_user;
- Main.cookie = cookies;
- Toast pass = Toast.makeText(context, cookies, Toast.LENGTH_LONG);
- pass.show();
- }
- }
- @Override
- protected void onProgressUpdate(Void... values) {
- super.onProgressUpdate(values);
- }
- }
- Set-Cookie:PHPSESSID=....;path=/
- Set-Cookie:usrnm......;expires.....;path=/;domain=www.example2.com
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement