与Android的饼干PHP登录 [英] php login on android with cookie

查看:160
本文介绍了与Android的饼干PHP登录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在这里一些指点。所以基本上要使用什么,我所做的就是我创建了一个表格登录到Web服务器。因此,从响应code,我能够通过Wireshark来获得200状态code。这个浏览器登录系统的正常路径是

i need some pointers here. So basically what I've done is i've created a form to be used to login to a web server. So, from the response code i am able to get a status code of 200 through wireshark. The normal path of this browser login system is

密码+ ID>的index.php>(如果为true)> index2.php但是,在Android应用程式,显然它并不重定向虽然,我不知道如果它的猜想?我已经使用Jsoup.connect(URL).cookie(SessionID的,我不知道为什么,始终为null)获得()审判;但因为它总是空,这是行不通的。饼干头如果正确的话是PHPSESSID = somenumiericavalue还是我看着从Wireshark的错误的事情?而另一件事,正如我已经说过我尝试使用Jsoup.connect方法也HttpURLConnection的同时,下面的 Android的HTTP登录问题,但是,当涉及到我需要检查我迷路了:(头和价值的部分。

password + id > index.php >(if true) > index2.php but, on the android app, apparently it does not redirect though, i'm not sure if its suppose to? I've tried using Jsoup.connect(URL).cookie(sessionid which i don't know why, is always null).get(); but as it is always null, it is not going to work. The cookie header if correct is "PHPSESSID=somenumiericavalue" or am i looking at the wrong thing from wireshark? and another thing, as i've said i tried using Jsoup.connect method and also HttpURLConnection also, following Android HTTP login questions but, when it comes to the part where i need to check the header and value i'm lost :(.

if(response.getStatusLine().getStatusCode() == 200){
                        HttpEntity entity = response.getEntity();
                        Log.d("login", "success!");
                        if(entity != null){
                         cookies = client.getCookieStore();

我在这里丢失庞贝氏说做一些更多的东西。绝对失去了在这里。另一部分是它采用的wireshark下一个部分。失去了太多。 (

i'm lost here when Pompe says do some more stuff. Absolute lost here. Another part is the next part where it uses wireshark. lost too. :(

推荐答案

该Cookie一般应该由HttpClient的正确处理:你只需要使用同一个HttpClient的实例来登录你用你的实际要求,以及饼干应该在所有请求进行维护。作为一个例子,这是我用一个特定的登录序列:在我的情况下,我用一个位置重定向是成功的象征,但是你可以用200 OK状态行模式。如果返回true,则在HttpClient的实例会议的cookie存储有相应的cookie,我可以访问任何保护的URL就好了。

The cookie should generally be handled by the HttpClient correctly: you just have to use the same HttpClient instance to log in that you use for your actual requests, and the cookie should be maintained across all requests. As an example, this is a specific login sequence I use: in my case I use a Location redirect as a success symbol, but you can use a 200 OK status line instead. If this returns true then the cookie store in the HttpClient instance session has the appropriate cookie and I can access any protected URLs just fine.

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;
    }

这篇关于与Android的饼干PHP登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆