dou12754 2011-09-11 21:57
浏览 65

从Android PHP登录获得响应

I'm trying to determine whether the user name and password I've sent to a php login form is valid. I've read some posts that suggest looking at the response text and checking for the title of the page that is returned. Other posts mention using a session ID in some way. Just what is the best way to detrmine if the user name/password combo is valid once I've posted to the form? Any help would be greatly appreciated. Thanks in advance.

Update...

I was able to resolve this issue using the following code snippet:

response = httpClient.execute(httpPost);
cookies = ((AbstractHttpClient) httpClient).getCookieStore ();
myCookie = cookies.getCookies ();
//  if cookies are empty, login did not work.
if (!myCookie.isEmpty ()) 
    { 
    for (int i = 0; i < myCookie.size(); i++) 
          { 
        String str = myCookie.get(i).toString(); 
        //  look for PHP session cookie and save it.
        if (str.contains ("PHPSESSID"))
            {
            phpsessid = myCookie.get (i).toString ();
            int index = phpsessid.indexOf("value");
            phpsessidGuid = phpsessid.substring(index+7, index+39);
            }
          } 
    }

Hope this helps others with the same problem.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 关于#python#的问题:求帮写python代码
    • ¥15 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
    • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
    • ¥15 来真人,不要ai!matlab有关常微分方程的问题求解决,
    • ¥15 perl MISA分析p3_in脚本出错
    • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
    • ¥15 ubuntu虚拟机打包apk错误
    • ¥199 rust编程架构设计的方案 有偿
    • ¥15 回答4f系统的像差计算
    • ¥15 java如何提取出pdf里的文字?