解决方案 »
- android webservice SoapObject Object 类型转换
- 请教高手,通话中如何播放提示音,如分钟提示音
- android socket 长连接的问题
- HELP!求助!菜鸟求助!
- 关于拨号界面中optionsmenu的问题(急)
- 求指导:Android下怎样自定义手机上菜单键的内容?
- 关于Intent.FLAG_ACTIVITY_NEW_TASK这个FLAG
- 广告“推出”是怎么做到的?
- 使用fragmentManeger添加一个fragment时,使用linerlayout布局的子fragment无法充满父容器.
- android 高德地图 请问多个marker点在屏幕上全部显示 如果点与点之间距离太远 怎么自动缩放比例
- 请问如何监听一段时间内用户是否对设备有操作?
- Assets 目录下的文件夹大小限制吗?
2:返回登录页面,太容易理解了,很简单,你鉴权失败了
你若调用API你需要看人家写的文档,极可能存session或cookie
登录成功后直接请求,是否就正常了
{
String uriAPI = "http://test.com/index.php";
String strName ="tester";
String strPwd = "1234";
String strRet = "";
try
{
DefaultHttpClient httpclient = new DefaultHttpClient();
HttpResponse response;
HttpPost httpost = new HttpPost(uriAPI);
List <NameValuePair> nvps = new ArrayList <NameValuePair>();
nvps.add(new BasicNameValuePair("name", strName));
nvps.add(new BasicNameValuePair("pwd", strPwd));
httpost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));
response = httpclient.execute(httpost);
HttpEntity entity = response.getEntity();
//entity = response.getEntity();
Log.d(TAG, "HTTP POST getStatusLine: " + response.getStatusLine());
/* HTML POST response BODY */
strRet = EntityUtils.toString(entity);
Log.i(TAG, strRet);
strRet = strRet.trim().toLowerCase();
List<Cookie> cookies = httpclient.getCookieStore().getCookies();
if (entity != null)
{
entity.consumeContent();
}
Log.d(TAG, "HTTP POST Initialize of cookies.");
cookies = httpclient.getCookieStore().getCookies();
if (cookies.isEmpty())
{
Log.d(TAG, "HTTP POST Cookie not found.");
Log.i(TAG, entity.toString());
}
else
{
for (int i = 0; i < cookies.size(); i++)
{
Log.d(TAG, "HTTP POST Found Cookie: " + cookies.get(i).toString());
}
}
System.out.println("result:"+strRet);//返回的结果!
}
catch(Exception e)
{
e.printStackTrace();
}
}