Android的登录网站 - 总是返回登录页面数据 [英] Android Login to Website - Always returns login page data
问题描述
我有一个登录表单目前正在登录参数,并登录到使用HTTP POST请求一个网站。我不确定服务器类型,这样可能是问题。一旦需要登录凭据,它覆羽InputStream的一个字符串(所有的HTML),并设置到一个TextView。这里的登录:
I have a login form currently taking login parameters and logging into a website using HTTP Post Request. I am unsure of the server type so that could be the problem. Once it takes the login credentials, it coverts the inputstream to a string (all the html) and sets that to a textview. Here's the login:
private void postLoginData() throws ClientProtocolException, IOException {
// Create a new HttpClient and Post Header
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("loginurl"); // Changed for question.
try {
// Add your data
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("sid", "username"));
nameValuePairs.add(new BasicNameValuePair("pin", "pass"));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
// Execute HTTP Post Request
HttpResponse response = httpclient.execute(httppost);
String finalres = inputStreamToString(response.getEntity().getContent()).toString();
tvStatus.setText(finalres);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
} catch (IOException e) {
// TODO Auto-generated catch block
}
}
和这里的inputStreamToString()
And here's the inputStreamToString()
private StringBuilder inputStreamToString(InputStream is) throws IOException {
String line = "";
StringBuilder total = new StringBuilder();
// Wrap a BufferedReader around the InputStream
BufferedReader rd = new BufferedReader(new InputStreamReader(is));
// Read response until the end
while ((line = rd.readLine()) != null) {
total.append(line);
}
// Return full string
return total;
}
问题是,它永远只是返回登录页面的HTML。当用户无法在网站上登录,它有一个小的消息来表示。即使我添加不正确的凭据,它不会显示任何不同。同样,如果我添加正确的登录,它仍然显示我刚登录页面的HTML。
The problem is that it ALWAYS just returns the HTML for the login page. When a user fails login on the site, it has a little message to indicate so. Even if I add incorrect credentials, it doesn't display anything different. Likewise, if I add the correct login, it still shows me just the login page HTML.
推荐答案
我想这个问题是类似的这个问题。检查出来,也有一些解决方案,这可能会解决它为你工作。
I guess the problem is similar to this question. Check it out, there are some solutions, which might work for you in solving it.
这篇关于Android的登录网站 - 总是返回登录页面数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!