我正在尝试获取移动网站登录失败或成功的响应。这是我的代码的一部分。
编辑
public String login(String User, String Pass) throws Exception{
// Create a new HttpClient and Post Header
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(AmwayURL);
String result = "nothing";
try {
// Add user name and password
String username = User;
String password = Pass;
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("userid", username));
nameValuePairs.add(new BasicNameValuePair("userpswd", password));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
CookieStore cookieStore = new BasicCookieStore();
HttpContext localContext = new BasicHttpContext();
localContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
HttpResponse response = httpclient.execute(httppost, localContext);
result = inputStreamToString(response.getEntity().getContent()).toString();
HttpEntity entity = response.getEntity();
System.out.println("----------------------------------------");
System.out.println(response.getStatusLine());
if (entity != null) {
System.out.println("Response content length: " + entity.getContentLength());
}
List<Cookie> cookies = cookieStore.getCookies();
for (int i = 0; i < cookies.size(); i++) {
System.out.println("Local cookie: " + cookies.get(i));
}
// Consume response content
//EntityUtils.consume(entity);
System.out.println("----------------------------------------");
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
// When HttpClient instance is no longer needed,
// shut down the connection manager to ensure
// immediate deallocation of all system resources
httpclient.getConnectionManager().shutdown();
}
return result;
}
我确实得到了回复,如果我检查它,我可以看到我确实执行了登录,但我的问题是如何使用编程方式来确定登录是否成功?
我不能使用重定向代码,因为该站点位于同一页面上。