我正在使用 PHP 开发页面导入器,但在使用存储格式创建页面时遇到了问题。基本上我收到格式错误的 xhtml 错误:
HTTP/1.1 400 Bad Request
Date: Thu, 14 Jan 2016 18:13:48 GMT
Server: Apache-Coyote/1.1
X-ASEN: SEN-6458441
X-Seraph-LoginReason: OK
X-AUSERNAME: XXX
Cache-Control: no-cache, must-revalidate
Expires: Thu, 01 Jan 1970 00:00:00 GMT
X-Content-Type-Options: nosniff
Content-Type: application/json
Connection: close
Transfer-Encoding: chunked
{
"statusCode": 400,
"data": {
"authorized": false,
"valid": true,
"errors": []
},
"message": "Error parsing xhtml"
}
目的是创建 phpDocumentor 之类的源文档,因此我手动创建了页面,其中包含正确显示类文档所需的所有宏。问题是当我使用“查看存储格式”选项时,我得到的 XML 无效:
<ac:layout><ac:layout-section ac:type="single"><ac:layout-cell>
<p>Test</p><ac:structured-macro ac:macro-id="3e74101c-857f-4c47-8618-a27c627eea2c" ac:name="info" ac:schema-version="1"><ac:parameter ac:name="title">Fully qualified class name</ac:parameter><ac:rich-text-body>\Zend\Authentication\Adapter\Digest</ac:rich-text-body></ac:structured-macro>
<p><a href="https://github.com/zendframework/zend-authentication/blob/master/src/Adapter/Digest.php">Browse source code</a></p></ac:layout-cell></ac:layout-section><ac:layout-section ac:type="two_left_sidebar"><ac:layout-cell>
<h2>Class contents</h2>
<p><ac:structured-macro ac:macro-id="726aa6fa-6e48-4005-95ad-0fb28aae8162" ac:name="toc" ac:schema-version="1"><ac:parameter ac:name="maxLevel">4</ac:parameter><ac:parameter ac:name="minLevel">3</ac:parameter></ac:structured-macro></p>
<p> </p></ac:layout-cell><ac:layout-cell>
<h2>Description</h2>
<p><ac:structured-macro ac:macro-id="c7feab99-a70b-4ab8-bbac-846ed981bed0" ac:name="excerpt" ac:schema-version="1"><ac:parameter ac:name="atlassian-macro-output-type">INLINE</ac:parameter><ac:rich-text-body>
<p>Digest adapter for Zend Authentication mechanism</p></ac:rich-text-body></ac:structured-macro> </p>
<h2>Class details</h2>
<table style="letter-spacing: 0.1px;">
<tbody>
<tr>
<th>Package</th>
<td>\Zend\Authentication\Adapter</td></tr>
<tr>
<th>Inherited from</th>
<td><span style="color: rgb(68,68,68);">\Zend\Authentication\Adapter\AbstractAdapter</span></td></tr></tbody></table>
<h3>Methods</h3>
<hr /><ac:structured-macro ac:macro-id="43484e81-d0fd-4d40-b990-a7d90cd2b565" ac:name="panel" ac:schema-version="1"><ac:parameter ac:name="borderStyle">solid</ac:parameter><ac:rich-text-body>
<h4> <span style="color: rgb(51,51,51);">::__construct()</span></h4>
<hr />
<p><span style="color: rgb(51,51,51);"> </span></p>
<p>Sets adapter options</p><ac:structured-macro ac:macro-id="323db0b7-4961-4b55-8332-43790ef9b2bc" ac:name="code" ac:schema-version="1"><ac:parameter ac:name="language">php</ac:parameter><ac:parameter ac:name="theme">Confluence</ac:parameter><ac:plain-text-body><![CDATA[__construct(mixed $filename = null, mixed $realm = null, mixed $identity = null, mixed $credential = null)]]></ac:plain-text-body></ac:structured-macro>
<h5>Parameters</h5><ac:structured-macro ac:macro-id="eda8fe1a-8ccd-4b7b-8942-99fd9c2dba18" ac:name="expand" ac:schema-version="1"><ac:rich-text-body>
<table>
<tbody>
<tr>
<th>Parameter</th>
<th>Data type</th>
<th>Description</th></tr>
<tr>
<td>$filename</td>
<td>mixed</td>
<td> </td></tr>
<tr>
<td>$realm</td>
<td>mixed</td>
<td> </td></tr></tbody></table></ac:rich-text-body></ac:structured-macro></ac:rich-text-body></ac:structured-macro></ac:layout-cell></ac:layout-section></ac:layout>
所以当我在 REST API 调用中使用它时,我收到了之前提到的错误。调用如下所示:
<?php
use GuzzleHttp\Client;
use GuzzleHttp\Post\PostBody;
use GuzzleHttp\Stream\StreamInterface;
use GuzzleHttp\Exception\RequestException;
function send_request() {
// My API (2) (POST http://confluence.dev/rest/api/content)
$client = new Client();
$request = $client->createRequest('POST', 'http://confluence.dev/rest/api/content');
$postBody = $request->getBody();
try {
$request->addHeaders([
'Authorization'=>'Basic XXX',
'Content-Type'=>'application/json',
]);
$body = [
"body" => [
"storage" => [
"value" => "<ac:layout-section ac:type=\"single\"><ac:layout-cell><ac:structured-macro ac:macro-id=\"3e74101c-857f-4c47-8618-a27c627eea2c\" ac:name=\"info\" ac:schema-version=\"1\"><ac:parameter ac:name=\"title\">Fully qualified class name</ac:parameter><ac:rich-text-body>\\Zend\\Authentication\\Adapter\\Digest</ac:rich-text-body></ac:structured-macro>
<p><a href=\"https://github.com/zendframework/zend-authentication/blob/master/src/Adapter/Digest.php\">Browse source code</a></p></ac:layout-cell></ac:layout-section><ac:layout-section ac:type=\"two_left_sidebar\"><ac:layout-cell>
<h2>Class contents</h2>
<p><ac:structured-macro ac:macro-id=\"726aa6fa-6e48-4005-95ad-0fb28aae8162\" ac:name=\"toc\" ac:schema-version=\"1\"><ac:parameter ac:name=\"maxLevel\">4</ac:parameter><ac:parameter ac:name=\"minLevel\">3</ac:parameter></ac:structured-macro></p>
<p> </p></ac:layout-cell><ac:layout-cell>
<h2>Description</h2>
<p><ac:structured-macro ac:macro-id=\"c7feab99-a70b-4ab8-bbac-846ed981bed0\" ac:name=\"excerpt\" ac:schema-version=\"1\"><ac:parameter ac:name=\"atlassian-macro-output-type\">INLINE</ac:parameter><ac:rich-text-body>
<p>Digest adapter for Zend Authentication mechanism</p></ac:rich-text-body></ac:structured-macro> </p>
<h2>Class details</h2>
<table style=\"letter-spacing: 0.1px;\">
<tbody>
<tr>&& count($stdBody) == 0
<th>Package</th>
<td>\\Zend\\Authentication\\Adapter</td></tr>
<tr>
<th>Inherited from</th>
<td><span style=\"color: rgb(68,68,68);\">\\Zend\\Authentication\\Adapter\\AbstractAdapter</span></td></tr></tbody></table>
<h3>Methods</h3>
<hr /><ac:structured-macro ac:macro-id=\"43484e81-d0fd-4d40-b990-a7d90cd2b565\" ac:name=\"panel\" ac:schema-version=\"1\"><ac:parameter ac:name=\"borderStyle\">solid</ac:parameter><ac:rich-text-body>
<h4> <span style=\"color: rgb(51,51,51);\">::__construct()</span></h4>
<hr />
<p><span style=\"color: rgb(51,51,51);\"> </span></p>
<p>Sets adapter options</p><ac:structured-macro ac:macro-id=\"9de243a9-ca88-45e1-a6d4-7ff9b542babd\" ac:name=\"code\" ac:schema-version=\"1\"><ac:parameter ac:name=\"language\">php</ac:parameter><ac:parameter ac:name=\"theme\">Confluence</ac:parameter><ac:plain-text-body><![CDATA[__construct(mixed $filename = null, mixed $realm = null, mixed $identity = null, mixed $credential = null)]]></ac:plain-text-body></ac:structured-macro>
<h5>Parameters</h5><ac:structured-macro ac:macro-id=\"a2230db4-ea43-4e99-89d9-2661a57fd5c3\" ac:name=\"expand\" ac:schema-version=\"1\"><ac:rich-text-body>
<table>
<tbody>
<tr>
<th>Parameter</th>
<th>Data type</th>
<th>Description</th></tr>
<tr>
<td>$filename</td>
<td>mixed</td>
<td> </td></tr>
<tr>
<td>$realm</td>
<td>mixed</td>
<td> </td></tr></tbody></table></ac:rich-text-body></ac:structured-macro></ac:rich-text-body></ac:structured-macro></ac:layout-cell></ac:layout-section>",
"representation" => "storage"
]
],
"title" => "Adam tests",
"space" => [
"key" => "TEST"
],
"type" => "page"
];
$request->setBody(GuzzleHttp\Stream\Stream::factory(json_encode($body)));
$response = $client->send($request);
echo "Response HTTP : " . $response->getStatusCode();
}
catch (RequestException $e) {
echo "HTTP Request failed\n";
echo $e->getRequest();
if ($e->hasResponse()) {
echo $e->getResponse();
}
}
}
我正在使用 Confluence 5.9.4。
我尝试创建此页面的方式有问题吗?页面中可用的存储格式是否与 API 不兼容?