【发布时间】:2016-03-22 11:15:50
【问题描述】:
我一直试图弄清楚为什么在尝试向我的服务器“发送出席信息”(在同一台机器上本地运行)时出现“XML 解析错误:“格式不正确(无效令牌)”错误),在成功将用户连接到服务器后。
一切都很好,直到我尝试访问客户端对象上的$client->send(new Presence); 方法,例如在他连接之后。这是我在运行$client = new Client($options); 并转储进程中返回的客户端对象后得到的结果。
客户端对象转储
但是,如果我在控制器中运行代码行,例如 $client->send(new Presence); 之后,我会收到这个讨厌的错误
XML 解析错误
我的控制器测试方法中的代码对此非常简单,只需使用 packagist 上 fabiang/xmpp 包的文档中的指南。
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use Fabiang\Xmpp\Client;
use Fabiang\Xmpp\Options;
use Fabiang\Xmpp\Protocol\Roster;
use Fabiang\Xmpp\Protocol\Presence;
use Fabiang\Xmpp\Protocol\Message;
class XmppController extends Controller
{
public function __construct() {
}
public function test() {
$address = "dergree-pc:9090"; // if using HTTP in front, it will give the "cant open stream exception"
$username = "test";
$password = "password";
$options = new Options($address);
$options->setUsername($username)->setPassword($password);
$client = new Client($options);
// ALL THE ABOVE CODE WORKS
$client->send(new Presence); // this or any other line below gives the XML parsing error
// optional connect manually
//$client->connect();
//$client->send(new Roster);
}
}
【问题讨论】: