繁体   English   中英

使用PHP变量/ REST API融合更新页面

[英]Update a Page with PHP Variables / REST API Confluence

我想更新与一些php变量融合的页面。 所以这是我的PHP代码来更新页面:

$curl = curl_init();

$post = "{\"id\":\"65604\",\"type\":\"page\",\"title\":\"page\",\"space\":{\"key\":\"***\"},\"body\":{\"storage\":{\"value\":\"<p>Here comes the other variable: $product_response </p>\",\"representation\":\"storage\"}},\"version\":{\"number\":11}}";

curl_setopt_array($curl, array(
  CURLOPT_PORT => "6003",
  CURLOPT_URL => "http://localhost:6003/rest/api/content/65604",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "PUT",
  CURLOPT_POSTFIELDS => $post,
  CURLOPT_COOKIE => "JSESSIONID=3A16CBFE8B99E619D62BD4CD6573F184",
  CURLOPT_HTTPHEADER => array(
    "authorization: Basic xyYS123_test_test-45Sdasds==",
    "content-type: application/json"
  ),
));

供你参考:

  • 如果我在另一个脚本中打印$ post,则显示变量值

  • 没有变量,curl会话可以工作,我可以更新页面

那就是错误:

{"statusCode":500,"message":"org.codehaus.jackson.JsonParseException: Illegal unquoted character ((CTRL-CHAR, code 10)): has to be escaped using backslash to be included in string value\n at [Source: com.atlassian.confluence.plugins.restapi.filters.LimitingRequestFilter$1@5dff62ce; line: 1, column: 119]","reason":"Internal Server Error"}

您所形成的帖子的json值格式错误,为什么不使用json_encode(); 通过声明数组中的所有值,您可以像这样更改代码:

$curl = curl_init();
$post = array(
    "id"=>"65604",
    "type"=>"page",
    "title"=>"page",
    "space"=>["key"=>"***"],
    "body" =>["storage"=>["value"=>"<p>Here comes the other variable: ".$product_response." </p>", "representation"=>"storage"]],
    "version"=>["number"=>11]
);

curl_setopt_array($curl, array(
CURLOPT_PORT => "6003",
CURLOPT_URL => "http://localhost:6003/rest/api/content/65604",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PUT",
CURLOPT_POSTFIELDS => json_encode($post),
CURLOPT_COOKIE => "JSESSIONID=3A16CBFE8B99E619D62BD4CD6573F184",
CURLOPT_HTTPHEADER => array(
"authorization: Basic xyYS123_test_test-45Sdasds==",
"content-type: application/json",
    'Accept: application/json'
),
));

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM