[英]HttpResponse differs in Android and Java
I am looking for some help! 我正在寻找帮助! I have some code doing server auth and retrieving the response from server.
我有一些执行服务器身份验证并从服务器检索响应的代码。 When i execute it in eclipse in my java project I've got reddirrect response like :
当我在Java项目的eclipse中执行它时,我得到了reddirrect响应,例如:
<html><head><meta http-equiv="refresh" content="0;url=SiteIamLoggingPageURL/"/></head></html>
But when i am excecuting the same code in my android app, ive got response equal to the failed login scenario. 但是,当我在我的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());
What is the problem? 问题是什么? oo Thank you for your time!
oo谢谢您的时间!
Sound like you forgot adding 听起来好像您忘了添加
<uses-permission android:name="android.permission.INTERNET" />
in AndroidManifest.xml. 在AndroidManifest.xml中。 Have a look at this tutorial
看看这个教程
It could be because your not executing the HTTP request on a separate Thread
. 可能是因为您没有在单独的
Thread
上执行HTTP请求。 Read more about this here: 在这里阅读有关此内容的更多信息:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.