用户登陆,只输入用户名,并且代码在软件启动时已获得手机硬件ID,通过获取用户名和ID,POST传入服务器,
服务器地址:http://117.28.239.31:8007/Controllers/LoginByDIDHandler.ashx
ID格式:123d257b-2998-33a7-9439-2aebc950efe4
求如果通过POST传userName和Did,并获取返回信息。
最好不要第三方类库这样的建议,求完整代码,谢谢!
private void login ( final String username , final String password ) {
if (! netMgr . isNetworkAvailable ()) {
Toast . makeText ( this , "请检查网络连接!" , Toast . LENGTH_LONG ). show ();
return ;
}
loginProgress = new ProgressDialog ( this );
loginProgress . setCancelable ( false );
loginProgress . setCanceledOnTouchOutside ( false );
loginProgress = loginProgress . show ( this , null , "登陆中..." );
new Thread ( new Runnable () {
@Override
public void run () {
Log . d ( "yanghongbing" , "start network!" );
HttpClient client = new DefaultHttpClient ();
HttpPost httpPost = new HttpPost ( Config . LOGIN_URL );
List < NameValuePair > params = new ArrayList < NameValuePair >();
params . add ( new BasicNameValuePair ( "username" , username ));
params . add ( new BasicNameValuePair ( "password" , password ));
HttpResponse httpResponse = null ;
try {
httpPost . setEntity ( new UrlEncodedFormEntity ( params , HTTP . UTF_8 ));
httpResponse = client . execute ( httpPost );
if ( httpResponse . getStatusLine (). getStatusCode () == 200 ) {
Log . d ( "yanghongbing" , "network OK!" );
HttpEntity entity = httpResponse . getEntity ();
String entityString = EntityUtils . toString ( entity );
String jsonString = entityString . substring ( entityString . indexOf ( "{" ));
Log . d ( "yanghongbing" , "entity = " + jsonString );
JSONObject json = new JSONObject ( jsonString );
sendMessage ( MSG_LOGIN_RESULT , json );
Log . d ( "yanghongbing" , "json = " + json );
}
} catch ( UnsupportedEncodingException e ) {
Log . d ( "yanghongbing" , "UnsupportedEncodingException" );
e . printStackTrace ();
} catch ( ClientProtocolException e ) {
Log . d ( "yanghongbing" , "ClientProtocolException" );
e . printStackTrace ();
} catch ( IOException e ) {
Log . d ( "yanghongbing" , "IOException" );
sendMessage ( MSG_SERVER_UNAVAILABLE , null );
e . printStackTrace ();
} catch ( JSONException e ) {
Log . d ( "yanghongbing" , "IOException" );
// TODO Auto-generated catch block
e . printStackTrace ();
}
}
}). start ();
}
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。