我正在寻求帮助! 我有一些代码执行服务器身份验证并从服务器检索响应。当我在我的 java 项目的 eclipse 中执行它时,我得到了 reddirrect 响应,如:
<html><head><meta http-equiv="refresh" content="0;url=SiteIamLoggingPageURL/"/></head></html>
但是当我在我的 android 应用程序中执行相同的代码时,我得到的响应等于登录失败的情况。
HttpPost post = new HttpPost(loginPageAdress);
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
//nameValuePairs.add(new BasicNameValuePair("remember", "1"));
nameValuePairs
.add(new BasicNameValuePair("email", "email"));
nameValuePairs.add(new BasicNameValuePair("password", "password"));
post.setEntity(new UrlEncodedFormEntity(nameValuePairs, "utf-8"));
StringBuilder stringBuilder = new StringBuilder();
HttpResponse response = client.execute(post, httpContext);
BufferedReader rd = new BufferedReader(new InputStreamReader(response
.getEntity().getContent(), "UTF-8"));
String line = "";
while ((line = rd.readLine()) != null) {
stringBuilder.append(line).append("\n");
}
System.out.println(stringBuilder.toString());
问题是什么? o.o 感谢您的宝贵时间!
最佳答案
听起来好像你忘了添加
<uses-permission android:name="android.permission.INTERNET" />
在 AndroidManifest.xml 中。 看看this tutorial
关于java - HttpResponse 在 Android 和 Java 中不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11307828/