Web Services 解析第2行上的SOAP负载时出现XML错误:文档结尾无效

a8jjtwal  于 2022-11-24  发布在  其他
关注(0)|答案(1)|浏览(165)

我是Web服务的新手。为了了解Web服务,我尝试创建一个Web服务,该服务首先具有设置会话的登录函数。但当我想要使用会话中保存的信息时,我看到以下错误:“解析第2行上的SOAP负载时出现XML错误:无效的文档结束“我必须提到,如果我手动设置用户ID,不使用会话,不会有任何错误!可以任何人请帮我找出我的代码有什么问题吗?这里是客户端和服务器代码:(不关心一些参数,如$param在show_log函数)

***server page:
    $server = new soap_server();
    $server->register('login');
    $server->register('show_log');
    function login($username, $password) {
    global $db;

    $result = false;
    $login_stmt = "SELECT * FROM users WHERE username='$username' AND password='$password'";
    $login_query = $db->query($login_stmt);
    checkDbError($login_query, __FILE__, __LINE__);

    If (mysqli_num_rows($login_query) == 0) {
        $result = FALSE;
    } else {
        $user = $login_query->fetch_assoc();
        $result = true;
        $_SESSION['id'] = $user['id'];
    }
    return $result;
}
function show_log($param) {
    $id = $_SESSION['id'];
    global $db;
    $log_stmt = "SELECT * FROM log WHERE `user-id`='$id' order by `date` desc";
    $log_query = $db->query($log_stmt);
    checkDbError($log_query, __FILE__, __LINE__);
    If (mysqli_num_rows($log_query) == 0) {
        $result = " No log was found";
    } else {
        while ($log_list = $log_query->fetch_assoc()) {
            $result[] = array("user_id" => $log_list['user-id'],
                "firstname" => $log_list['first-name'], "lastname" => $log_list['last-name'],
                "date" => $log_list['date'], "ip" => $log_list['ip']);
        }
    }
    return $result;
}
if (!isset($HTTP_RAW_POST_DATA))
    $HTTP_RAW_POST_DATA = file_get_contents('php://input');
$server->service($HTTP_RAW_POST_DATA);
exit();

**login page:
<?php
if (isset($_POST['login'])) {
    $client = new nusoap_client('http://localhost/webService2/server.php');
    $user = check_data($_POST['username']);
    $password = check_data($_POST['password']);
    $param1=array("username"=>$user,"password"=>$password);
    $response = $client->call('login', $param1);

    if ($response == FALSE) {
        ?>
        <div class="col-lg-12 ">
            <br><br><br>
            <div class="col-lg-4"></div>
            <div class="col-lg-3 message">
                <p>Invalid username and password</p>
            </div>
        </div>
        <?php
    } else {
        header("Location:profile.php");
//        echo $response;
    }
}
?>
**profile page:
$param = array('word' => "aaa");
$response1 = $client->call('show_log', $param);
$error = $client->getError();
echo $error;
w9apscun

w9apscun1#

当你通过soap服务访问的页面包含一些错误时,可能会发生这种情况。在你的php配置文件(php.ini)中搜索display_errors = "On"并将其更改为off(在windows中是php.ini文件,但在linux中可能不同)。

相关问题