其實我正在做測試,如果我的應用程序可以通過http post.Am發送一些額外的參數,我需要測試應用程序,但我每次運行它我甚至可以登錄我的參數是真實的。這是我正在使用的代碼。Android HttpPost登錄動作
new_auth_data=1&debug_data=1&client_api_ver=1.5.1.422×tamp=1314195661&password_hash=d2824b50d07cfed3d82a480d5d87437af11a4f7e&set_locale=en_US&device_os_type=iPhone%20Simulator%204.3.2&username_hash=6d229fe6593f5250653e3b29184a6e370fc7ffe5&device_sync_type=3&device_identification_string=iPhone%20Simulator%204.3.2&device_resolution=320x480&device_identificator=255634997
:
package com.android.login.test;
/* new_auth_data=1& - If there is new user ot password changes
* debug_data=1& - Debugging data sent from terminal
* client_api_ver=1.5.1.422& - API version of clients terminal
* timestamp=1314195661& - THE timestamp of first sync of new device
* password_hash=d2824b50d07cfed3d82a480d5d87437af11a4f7e& - A valid password hash
* set_locale=en_US& -
* device_os_type=iPhone%20Simulator%204.3.2& - The device OS code - for mobiles
* username_hash=6d229fe6593f5250653e3b29184a6e370fc7ffe5& - A valid username hash
* device_sync_type=3& - 3 is for iphone, 4 will be for android
* device_identification_string=iPhone%20Simulator%204.3.2& - Device identificator (friendly name)
* device_resolution=320x480& - No need of explanation
* device_identificator=255634997 - This identificator is catched with getDeviceId() function
*/
import java.util.ArrayList;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
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.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class LoginActivity extends Activity {
EditText username,password;
Button login;
TextView error;
ArrayList<NameValuePair> postParameters;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
username = (EditText)findViewById(R.id.username);
password = (EditText) findViewById(R.id.password);
error = (TextView) findViewById(R.id.error);
final HttpClient httpclient = new DefaultHttpClient();
final HttpPost httppost = new HttpPost("http://www.rpc.example.com");
postParameters = new ArrayList<NameValuePair>();
postParameters.add(new BasicNameValuePair("username_hash", username.getText().toString()));
postParameters.add(new BasicNameValuePair("password_hash", password.getText().toString()));
/*postParameters.add(new BasicNameValuePair("debug_data","1"));
postParameters.add(new BasicNameValuePair("client_api_ver","1.5.1.422"));
postParameters.add(new BasicNameValuePair("timestamp","1314195661"));
postParameters.add(new BasicNameValuePair("set_locale","en_US"));
postParameters.add(new BasicNameValuePair("device_os_type","Android 2.2"));
postParameters.add(new BasicNameValuePair("device_sync_type","3"));
postParameters.add(new BasicNameValuePair("device_identificator","255634997"));
postParameters.add(new BasicNameValuePair("device_identification_string",deviceId));*/
login = (Button) findViewById(R.id.login);
login.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try {
httppost.setEntity(new UrlEncodedFormEntity(postParameters));
HttpResponse response = httpclient.execute(httppost);
Log.d("myapp", "response " + response.getEntity());
String responseBody = EntityUtils.toString(response.getEntity());
error.setText(responseBody);
} catch (Exception e) {
username.setText(e.toString());
}
}
});
}
}
因爲我說的只是test.As結果執行HTTP POST後,我需要向服務器發送類似的東西我設置的所有PARAMS代碼
我該如何解決這個問題,以便我可以測試登錄?歡迎任何想法或建議! 在此先感謝!
我不確定我是否理解現在正在發生的事情......你是否說它總是會說「正確的用戶名或密碼」,即使它不正確?你能告訴我們服務器正在接收什麼? –
它總是說用戶名和密碼是不正確的。我怎樣才能看到服務器正在從我的應用程序或服務器接收...(抱歉,這是我第一次與服務器和用戶登錄過程同步)。 –