写了个方法,实现的登录功能,代码是参照的书上源码,但不懂具体的意思,哪位大侠能帮忙解释下。
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
解决方案 »
- app反编译操作失败,dex文件没有生成jar文件,神马情况?
- 关于用DexClassLoader加载JAR包中Service的问题
- listview的adapter中的item状态怎么保存
- 急急急:如何控制信息音,按键音,语音提示的开启与关闭。。。。。
- 求助android中实现通过音频线获取高低电平转换成二进制(1和0)
- android的MediaPlayer播放RTSP的问题
- 做Android开发和java开发 用那款笔记本好呢 求大神推荐
- 这样获取天气为什么获取不到数据。
- 如何在一个activity中监听开机键是否按下
- android4.2 MTK CTS 测试失败项
- 求大神帮忙!!如何在其他Active中调用MainActive的方法??
- 在android中的editText和界面
data后面两段又是什么用?