写了个方法,实现的登录功能,代码是参照的书上源码,但不懂具体的意思,哪位大侠能帮忙解释下。
private void httpPost() {
String URL = "**********";
String strUserName = userName.getText().toString();
String strPassword = password.getText().toString(); HttpPost httpRequest = new HttpPost(URL);
HttpResponse httpResponse = null;
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("userName", strUserName));
params.add(new BasicNameValuePair("password", strPassword));
params.add(new BasicNameValuePair("flag", "0"));
try {
httpRequest.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} try {
httpResponse = new DefaultHttpClient().execute(httpRequest);
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
if(httpResponse.getStatusLine().getStatusCode() == 200) {
byte[] data = new byte[2048];
try {
data = EntityUtils.toByteArray( (HttpEntity)httpResponse.getEntity());
ByteArrayInputStream bais = new ByteArrayInputStream(data);
DataInputStream dis = new DataInputStream(bais);
} catch (IOException e) {
e.printStackTrace();
}
// user = new String(dis.readUTF());
}
}
书上说,到此手机终端从Web服务器获取了所有类型的数据。请问源码中具体是那部分获得了服务器返回的数据啊,我好整理了加载到Activity,感激不尽啊!
服务器web服务urlandroid HttpPost
private void httpPost() {
String URL = "**********";
String strUserName = userName.getText().toString();
String strPassword = password.getText().toString(); HttpPost httpRequest = new HttpPost(URL);
HttpResponse httpResponse = null;
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("userName", strUserName));
params.add(new BasicNameValuePair("password", strPassword));
params.add(new BasicNameValuePair("flag", "0"));
try {
httpRequest.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} try {
httpResponse = new DefaultHttpClient().execute(httpRequest);
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
if(httpResponse.getStatusLine().getStatusCode() == 200) {
byte[] data = new byte[2048];
try {
data = EntityUtils.toByteArray( (HttpEntity)httpResponse.getEntity());
ByteArrayInputStream bais = new ByteArrayInputStream(data);
DataInputStream dis = new DataInputStream(bais);
} catch (IOException e) {
e.printStackTrace();
}
// user = new String(dis.readUTF());
}
}
书上说,到此手机终端从Web服务器获取了所有类型的数据。请问源码中具体是那部分获得了服务器返回的数据啊,我好整理了加载到Activity,感激不尽啊!
服务器web服务urlandroid HttpPost
解决方案 »
- 在线求解 proguard混淆的解释
- 关于Android中setPositiveButton和setNegativeButton的使用问题
- 【技术宅追女生】准备做一款APP去追一位暗恋很久的女生,求框架。。。。(及时更新状况)
- adb logcat怎么同时输出入两个模拟器的log
- android FM和Camera问题
- 大家帮我看看这个异常是怎么造成,该如何解决啊?谢谢啦
- 问一个关于软键盘的问题~~
- Android4.2.2启动向导Provision(SetupWizard)的问题请教
- 仿网易图片轮播
- 求哪位程序员大佬帮忙解决一下短信乱码还原的问题。
- 求大神帮忙!!如何在其他Active中调用MainActive的方法??
- 在android中的editText和界面
data后面两段又是什么用?