07-26-2012, 15:19
C++ Code
- package com.example.t;
-
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.InputStreamReader;
- import java.util.ArrayList;
- import java.util.List;
-
- import org.apache.http.HttpResponse;
- import org.apache.http.NameValuePair;
- import org.apache.http.client.ClientProtocolException;
- import org.apache.http.client.HttpClient;
- import org.apache.http.client.entity.UrlEncodedFormEntity;
- import org.apache.http.client.methods.HttpPost;
- import org.apache.http.impl.client.DefaultHttpClient;
- import org.apache.http.message.BasicNameValuePair;
-
- import android.app.Activity;
- import android.content.Intent;
- import android.os.AsyncTask;
- import android.os.Bundle;
- import android.support.v4.app.NavUtils;
- import android.util.Log;
- import android.view.Menu;
- import android.view.MenuItem;
- import android.widget.TextView;
-
- public class Action extends Activity {
- private TextView textView;
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_action);
- getActionBar().setDisplayHomeAsUpEnabled(false);
- Intent intent = getIntent();
- String user = intent.getStringExtra(Home.USER_NAME);
- String pass = intent.getStringExtra(Home.PASS_WORD);
- String dest = intent.getStringExtra(Home.END_POINT);
- download(dest, user, pass);
- }
-
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- getMenuInflater().inflate(R.menu.activity_action, menu);
- return true;
- }
-
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- switch (item.getItemId()) {
- case android.R.id.home:
- NavUtils.navigateUpFromSameTask(this);
- return true;
- }
- return super.onOptionsItemSelected(item);
- }
-
- public void download(String endpoint, String user, String pass) {
- getHTML task = new getHTML();
- task.execute(endpoint, user, pass);
- textView = (TextView) findViewById(R.id.textView1);
- textView.setText("User: "+ user +" Pass: "+ pass +" URL: "+ endpoint);
- }
-
- class getHTML extends AsyncTask<String, Integer, String> {
- @Override
- protected String doInBackground(String... params) {
- try {
- get_data(params[0], params[1], params[2]);
- } catch (IOException e) {
- e.printStackTrace();
- }
- return null;
-
- }
-
- protected void onPostExecute(String result) {
-
- }
-
-
- }
-
- public String get_data(String dest, String user, String pass) throws IOException{
- InputStream is = null;
-
- try {
- HttpClient httpclient = new DefaultHttpClient();
- HttpPost httppost = new HttpPost(dest);
- try {
- List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(4);
- nameValuePairs.add(new BasicNameValuePair("email", user));
- nameValuePairs.add(new BasicNameValuePair("password", pass));
- nameValuePairs.add(new BasicNameValuePair("do","user_login"));
- nameValuePairs.add(new BasicNameValuePair("akey", "android_app"));
- httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
- HttpResponse response;
- Log.d("http", "Dest: " + dest);
- Log.d("http", "User: " + user);
- Log.d("http", "Pass: " + pass);
- Log.d("http", "Device: " + System.currentTimeMillis());
- response = httpclient.execute(httppost);
- Boolean outp = request(response);
- if(outp) {
- Log.i("auth", "Login Successful");
- return "0x00";
- } else {
- Log.i("auth", "Login Failed with " + outp);
- return "0x01";
- }
- } catch (ClientProtocolException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
- } finally {
- if (is != null) {
- is.close();
- }
- }
- return null;
- }
-
- public static Boolean request(HttpResponse response){
- String result = "";
- try{
- InputStream in = response.getEntity().getContent();
- BufferedReader reader = new BufferedReader(new InputStreamReader(in));
- StringBuilder str = new StringBuilder();
- String line = null;
- while((line = reader.readLine()) != null){
- str.append(line);
- }
- in.close();
- result = str.toString();
- if(str.toString().equals("0")) {
- return true;
- } else {
- return false;
- }
- }catch(Exception ex){
- result = "Error";
- }
- return false;
- }
- }
crAyon makes no warranty with respect to documents or other information available from this place, assumes no legal liability or responsibility whatsoever for the accuracy, completeness, or usefulness of any such information, and does not represent that its use would not infringe privately owned rights. crAyon disclaims all warranties, express and implied, including the warranties of merchantability and fitness for a particular purpose.