http响应返回IllegalstateException

时间:2015-08-08 15:08:30

标签: php android json http

我正在创建一个软件,要求用户从软件登录。我用Json进行交流。然后将数据传输到我在下面发布的php脚本。可以一些。但它在我的Android代码中显示了一个illegalStateException。有人可以帮助我。

<?php

class functions  
{
function __construct() 
{
    require_once 'DB_Connect.php';
    $this->db = new DB_Connect();
    $this->db->connect();
}
function __destruct() 
{

}

function getUser()
{
    $json= file_get_contents("php://input");
    $str = iconv('UTF-8', 'UTF-8//IGNORE', utf8_encode($json));
    $str = json_decode($str,true);
    $ID = $str['username'];
    $user = mysqli_query($com, 'SELECT * FROM employers WHERE Employers_ID = {$ID}');
    $db_password = $user['Password'];
    if($user->num_rows >0)
    {
        //$json= file_get_contents("php://input");
        //$str = iconv('UTF-8', 'UTF-8//IGNORE', utf8_encode($json));            
        $password = $str['password'];
        $password = clearstring($password);
        compare($db_password,$password);
    }
    function compare($db_str, $app_str)
    {   
       // $salt = "ol2ujh354238095uwef";
        $app_str = $app_str/*.$salt*/;
        if(md5($app_str)==$db_str)
        {
            $response['success'] = '1';
        }
        else
        {
            $response['success'] = '0';
        }
        return json_encode($response);
        //$response = json_encode($response);
        die(json_encode($response));
        //mysqli_close($con);
    }            
    }
    function clearstring($str)
    {
        //$str = strip_tags($str);
        $str = stripcslashes($str);
        $str = htmlspecialchars($str);
        $str = trim($str);
    return $str;

    }

}



?>

这是我的php脚本:

java.lang.IllegalStateException: Target host must not be null, or set in parameters. scheme=null, host=null, path=192.168.100.106/EMS/functions.php
        at org.apache.http.impl.client.DefaultRequestDirector.determineRoute(DefaultRequestDirector.java:591)
        at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:293)
        at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
        at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
        at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
        at milind.com.ems.MainActivity$1$1.run(MainActivity.java:79)

这是我的StackTrace

NA

3 个答案:

答案 0 :(得分:2)

在创建HttpPost对象时,您似乎忘了提及协议。

你有:

httpPost = new HttpPost("192.168.100.106/EMS/functions.php");

它应该是

httpPost = new HttpPost("http://192.168.100.106/EMS/functions.php");

看到缺少http://。当然,如果您使用的是SSL,请使用https://

此外,在使用后端,API和JSON时,请考虑使用Retrofit库。

答案 1 :(得分:1)

添加http httpPost = new HttpPost("192.168.100.106/EMS/functions.php");

应该如此 httpPost = new HttpPost("http://192.168.100.106/EMS/functions.php");

答案 2 :(得分:0)

在您的Php脚本中,您尚未调用自定义函数。 只需添加这两行就可以了。

 $func = new functions();
 $func->getUser();