отправить массив строк Android на PHP

0

Как я могу отправить строковый массив android в php?

im с использованием suger crm с android.in suger crm rest.php имеет этот модуль

 Method [  public method login ] {


      - Parameters [3] {
        Parameter #0 [  $user_auth ]
        Parameter #1 [  $application ]
        Parameter #2 [  $name_value_list ]
      }
    }

$user_auth имеет два значения: user_auth.user_name и user_auth.password

как я могу отправить значения этому параметру $user_auth

моя заявка имеет следующие

 String user_name = userName.getText().toString();
 String password = pass.getText().toString();

мой login.java

public class Login extends ActionBarActivity implements View.OnClickListener {

    EditText userName, pass;
    Button login;

    private ProgressDialog pDialog;

    JSONParser jsonParser = new JSONParser();

    private static final String LOGIN_URL = "http://crm.wakensys.com/service/v2/rest.php";

    private static final String TAG_SUCCESS = "sucess";
    private static final String TAG_MESSAGE = "message";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.login);

        userName = (EditText) findViewById(R.id.editText_userN);
        pass = (EditText) findViewById(R.id.editText_pass);
        login = (Button) findViewById(R.id.btn_login);

        login.setOnClickListener(this);

    }


    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        Log.d("v", "Login button clicked");

        new AttemptLogin().execute();
    }

    class AttemptLogin extends AsyncTask<String, String, String>{

        @Override
        protected void onPreExecute() {
        super.onPreExecute();
        pDialog = new ProgressDialog(Login.this);
        pDialog.setMessage("Attempting login..");
        pDialog.setIndeterminate(false);
        pDialog.setCancelable(true);
        pDialog.show();
        pDialog.dismiss();
        }

        @Override
        protected String doInBackground(String... args) {

             // Check for success tag
            int success;
            String user_auth[];
            String user_name = userName.getText().toString();
            String password = pass.getText().toString();

            try {
                // Building Parameters
                List<NameValuePair> params = new ArrayList<NameValuePair>();
                params.add(new BasicNameValuePair("user_auth[]", user_name));
                params.add(new BasicNameValuePair("user_auth[]", password));


                Log.d("request!", "starting..");
                // getting product details by making HTTP request
                JSONObject json = jsonParser.makeHttpRequest(LOGIN_URL, "POST", params);
                if(json == null)
                    return null;

                // check your log for json response
                Log.d("Login attempt", json.toString());

                // json success tag
                success = json.getInt(TAG_SUCCESS);
                if (success == 1) {
                    Log.d("Login Successful!", json.toString());
                    Intent i = new Intent(Login.this, Success.class);
                    finish();
                    startActivity(i);
                    return json.getString(TAG_MESSAGE);
                }else{
                    Log.d("Login Failure!", json.getString(TAG_MESSAGE));
                    return json.getString(TAG_MESSAGE);

                }
            } catch (JSONException e) {
                e.printStackTrace();
            }

            return null;

        }
        /**
         * After completing background task Dismiss the progress dialog
         * **/
        protected void onPostExecute(String file_url) {
            // dismiss the dialog once product deleted
            pDialog.dismiss();
            if (file_url != null){
                Toast.makeText(Login.this, file_url, Toast.LENGTH_LONG).show();
            }
        }
    }
}

любая помощь..

Теги:
sugarcrm

1 ответ

0

Я сам не делаю Java, но если ваш PHP-массив выглядит так,

$user_auth = array("username" => "myUsernameHere", "password" => "myPasswordHere");

то вы можете просто использовать $json_user_auth = json_encode($user_auth, JSON_FORCE_OBJECT); и отправить $json_user_auth на Java, а затем расшифровать JSON, конечно?

  • 0
    Спасибо за reply.but я хочу отправить значение из приложения Android на сайт php.

Ещё вопросы

Сообщество Overcoder
Наверх
Меню