[英]HttpResponse differs in Android and Java
我正在尋找幫助! 我有一些執行服務器身份驗證並從服務器檢索響應的代碼。 當我在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());
問題是什么? oo謝謝您的時間!
聽起來好像您忘了添加
<uses-permission android:name="android.permission.INTERNET" />
在AndroidManifest.xml中。 看看這個教程
可能是因為您沒有在單獨的Thread
上執行HTTP請求。 在這里閱讀有關此內容的更多信息:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.