2014-01-07 4 views
0

많은 안드로이드에서 PHP로 유형 질문이 있지만 질문에 대답하는 것 같지는 않습니다. 나 안드로이드 앱에서 내 사용자 이름과 암호 문자열을 내 Drupal 웹 사이트 usercrreate.php 양식으로 보내고 싶지만 어떻게해야할지 모르겠다. 다음 내가 한안드로이드에서 PHP로 문자열 보내기

// Set final values of the UserName and the Password to be stored 
String usernameFinal = (String) usernameview.getText(); 
String passwordFinal = (String) passwordfield.getText(); 

내 PHP 형태 :

<?php 

define('DRUPAL_ROOT', $_SERVER['DOCUMENT_ROOT']); 

chdir(DRUPAL_ROOT); 

include_once './includes/bootstrap.inc'; 
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); 

//This will generate a random password, you could set your own here 
    $password = 'password'; 

    //set up the user fields 
    $fields = array(
    'name' => 'username', 
    'mail' => '[email protected]', 
    'pass' => $password, 
    'status' => 1, 
    'init' => 'email address', 
    'roles' => array(
     DRUPAL_AUTHENTICATED_RID => 'authenticated user', 
    ), 
); 

    //the first parameter is left blank so a new user is created 
    $account = user_save(NULL, $fields); 

    // If you want to send the welcome email, use the following code 

    // Manually set the password so it appears in the e-mail. 
    $account->password = $fields['pass']; 

    // Send the e-mail through the user module. 
    drupal_mail('user', 'register_no_approval_required', $email, NULL, array('account' => $account), variable_get('site_mail', '[email protected]')); 
    ?> 

내 애플 두 문자열을 만들어 내 APP에서

나는 다음 있습니다. PHP 폼을 테스트하면 사용자 계정을 만드는 데 성공한 것으로 나타납니다. 필드에 수동으로 적절한 데이터를 채 웁니다. 이제 APP가 문자열을 PHP 폼으로 보내 URL 자체를 실행하기를 원합니다.

아이디어가 있습니까? 자바에서

답변

1

:

HttpClient client=new DefaultHttpClient(); 
HttpPost getMethod=new HttpPost("http://localhost.index.php"); 
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(); 
nameValuePairs.add(new BasicNameValuePair("username","12345")); 
nameValuePairs.add(new BasicNameValuePair("password","54321")); 
getMethod.setEntity(new UrlEncodedFormEntity(nameValuePairs,HTTP.UTF_8)); 
client.execute(getMethod); 

당신의 PHP에서 :

$username = $_POST['username']; 
$password = $_POST['password']; 
+0

변수 "클라이언트"마지막 줄에 같이 없다? –

+0

죄송합니다. 나는 내 대답을 바꿨다. 확인해주십시오 – henry4343