[英]php login on android with cookie
我需要一些指示。 所以基本上我所做的是我創建了一個用於登錄 web 服務器的表單。 因此,從響應代碼中,我可以通過 Wireshark 獲得狀態代碼 200。 這個瀏覽器登錄系統的正常路徑是
密碼 + id > index.php >(如果為真)> index2.php 但是,在 android 應用程序上,顯然它不會重定向,但我不確定它是否會重定向? 我試過使用 Jsoup.connect(URL).cookie(sessionid 我不知道為什么,總是 null).get(); 但由於它始終是 null,它不會工作。 如果正確,cookie header 是“PHPSESSID=somenumiericavalue”還是我從wireshark 看錯了? 還有一件事,正如我所說,我嘗試使用 Jsoup.connect 方法和 HttpURLConnection 也遵循Android HTTP 登錄問題但是,當涉及到我需要檢查 Z099FB995346F31C749ZF6E0DB 丟失的部分時:
if(response.getStatusLine().getStatusCode() == 200){
HttpEntity entity = response.getEntity();
Log.d("login", "success!");
if(entity != null){
cookies = client.getCookieStore();
當龐貝說做更多的事情時,我迷路了。 絕對迷失在這里。 另一部分是使用wireshark 的下一部分。 也輸了。 :(
cookie 通常應該由 HttpClient 正確處理:您只需使用與實際請求相同的 HttpClient 實例登錄,並且應該在所有請求中維護 cookie。 例如,這是我使用的特定登錄序列:在我的例子中,我使用位置重定向作為成功符號,但您可以使用 200 OK 狀態行來代替。 如果返回 true,則 HttpClient 實例session
中的 cookie 存儲具有適當的 cookie,我可以訪問任何受保護的 URL。
public synchronized boolean login() throws Exception
{
HttpGet httpget;
HttpPost httpost = new HttpPost(base + "auth/login");
List<NameValuePair> nvps = new ArrayList<NameValuePair>();
nvps.add(new BasicNameValuePair("username", this.username));
nvps.add(new BasicNameValuePair("password", this.password));
httpost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));
HttpResponse r = session.execute(httpost);
// verify it succeeded
HttpEntity entity = r.getEntity();
Header lhdr = r.getFirstHeader("Location");
if (lhdr != null) {
// failed
System.err.println("Login request failed:");
if (entity != null && entity.getContentEncoding() != null) {
dump("Login Request",
new InputStreamReader(entity.getContent(), entity
.getContentEncoding().getValue()));
}
return false;
}
if (entity != null) entity.consumeContent();
return true;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.