80,351
社区成员
发帖
与我相关
我的任务
分享
private void processInternetLogin()
{
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();
}
}