用于在alfresco中创建子文件夹的API

时间:2013-12-12 07:17:12

标签: api alfresco alfresco-share

我有一个php脚本,它会向我的本地Alfresco副本发出curl请求来创建文件夹。但是,回应是“糟糕的要求”。下面是我的脚本,

<?php

$url = 'http://admin:admin123@localhost:8080/alfresco/service/api/site/folder/mysite/documentLibrary';

$postfields = array(
   "name"=> "abc",
);    

$curl = curl_init();

curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_COOKIESESSION, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($postfields));
$return = curl_exec($curl);
curl_close($curl);
echo $return;
?>

我收到以下回复:

 {
    "status" : 
  {
    "code" : 400,
    "name" : "Bad Request",
    "description" : "Request sent by the client was syntactically incorrect."
  },  

  "message" : "11120011 Invalid JSON: null",  
  "exception" : "org.springframework.extensions.webscripts.WebScriptException - 11120011 Invalid JSON: null",

  "callstack" : 
  [ 
      ""      ,"org.springframework.extensions.webscripts.WebScriptException: 11120011 Invalid JSON: null"
      ,"org.alfresco.repo.web.scripts.node.NodeFolderPost.executeImpl(NodeFolderPost.java:125)"
      ,"org.springframework.extensions.webscripts.DeclarativeWebScript.execute(DeclarativeWebScript.java:64)"
      ,"org.alfresco.repo.web.scripts.RepositoryContainer$3.execute(RepositoryContainer.java:433)"
      ,"org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:433)"
      ,"org.alfresco.repo.web.scripts.RepositoryContainer.transactionedExecute(RepositoryContainer.java:495)"
      ,"org.alfresco.repo.web.scripts.RepositoryContainer.transactionedExecuteAs(RepositoryContainer.java:533)"
      ,"org.alfresco.repo.web.scripts.RepositoryContainer.executeScript(RepositoryContainer.java:349)"
      ,"org.springframework.extensions.webscripts.AbstractRuntime.executeScript(AbstractRuntime.java:377)"
      ,"org.springframework.extensions.webscripts.AbstractRuntime.executeScript(AbstractRuntime.java:209)"
      ,"org.springframework.extensions.webscripts.servlet.WebScriptServlet.service(WebScriptServlet.java:118)"
      ,"javax.servlet.http.HttpServlet.service(HttpServlet.java:728)"
      ,"org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)"
      ,"org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)"
      ,"org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)"
      ,"org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)"
      ,"org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)"
      ,"org.alfresco.web.app.servlet.GlobalLocalizationFilter.doFilter(GlobalLocalizationFilter.java:61)"
      ,"org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)"
      ,"org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)"
      ,"org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)"
      ,"org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)"
      ,"org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)"
      ,"org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)"
      ,"org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)"
      ,"org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)"
      ,"org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)"
      ,"org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)"
      ,"org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041)"
      ,"org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603)"
      ,"org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)"
      ,"java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)"
      ,"java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)"
      ,"java.lang.Thread.run(Thread.java:744)"

  ],

  "server" : "Community v4.2.0 (4576) schema 6,022",
  "time" : "Dec 12, 2013 12:45:10 PM"
}

我做错了什么?

1 个答案:

答案 0 :(得分:2)

好的,想出这个。对于可能面临同样问题的其他人(或仅作为未来的参考),真正需要的是设置正确的请求标题!

curl_setopt($ curl,CURLOPT_HTTPHEADER,array('Content-type:application / json'));