doucang6739 2014-06-06 19:55
浏览 43
已采纳

来自php网站的java boolean

i want to create license system in java.

I created function to check if license is true.

My code:

    private static boolean isPurchased(String license)
{
    try
    {
        URL url = new URL("http://mineverse.pl/haslicense.php?license=" + license);
        BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
        String str = in.readLine();
        in.close();
        return Boolean.valueOf(str);
    } catch (Exception e)
    {
        e.printStackTrace();
    }
    return false;
}

and chceck function onenable

        if(this.isPurchased(license)){ 
                    String license = cfg.getString("Licensing_System.License");
        System.out.println("Licencja" + license + " kupiona! Dziekujemy!");
        System.out.println(this.isPurchased(license));

    }else {
        System.out.println("Licencja zostala sfalszowana! Zglaszam to do serwera autoryzacji!");
    }

And my link:

http://mineverse.pl/haslicense.php?license=diverse12345

as you can see this link return true, (i did echo 'true';) but java console always return false (i want true because website have true at this link) and it logs:

Licencja zostala sfalszowana! Zglaszam to do serwera autoryzacji!

Whats wrong? How can i return true on my website to allow java learn this boolean?>

  • 写回答

2条回答 默认 最新

  • doujiao3074 2014-06-06 20:04
    关注

    That's because your server is not just returning True or False. It is returning this instead:

    <html>
    </html>
                True
    

    and your code is only reading the first line <html> and parsing it as a boolean, which results in false.

    To fix it, either read the whole body looking for True/False or return just True/False on your body.

    The following code should work with the current html even if it contains the <html> tags:

            URL url = new URL("http://mineverse.pl/haslicense.php?license=" + license);
            BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
            String str = null;
            boolean ret = false;
            while ((str = in.readLine()) != null) {
                str = str.toLowerCase();
                if (str.contains("true")) {
                    ret = true;
                    break;
                }
            }
            in.close();
            return ret;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题