HTTP请求文件获取内容不工作


HTTP Request file get contents not working

我试图通过rest使用HTTP请求发送一个文件到BonitaBPM,但我试图发送的文件是空的,当我使用文件获取内容和HTTP请求不工作显然,由于

$file_contents = file_get_contents("C:/inetpub/wwwroot/upload/Director.png"); 
$data1 = array(
    "caseId"=> $case_id[1],
    "file"=>"C:/inetpub/wwwroot/upload/Director.png",
    "name"=>"doc_invoice",
    "fileName"=> $_FILES['file_attach']['name'],
    "description"=> "Invoice"
);
//Structure of process data to start case
$options1 = array(
    "http" => array(
        "method"  => "POST",
        "header"=>  "POST /bonita/API/bpm/caseDocument  HTTP/1.1'r'n".
            "Host: bonita.libertypr.com'r'n".
            "Cookie: ". $display[1]."'r'n".
            "Content-Type: application/json'r'n" .
            "Accept: application/json'r'n".
            "Cache-Control: no-cache'r'n".
            "Pragma: no-cache'r'n".
            "Connection: Keep-Alive'r'n'r'n",
        "content" => json_encode($data1)
    )
);
//decode process data and adds document to case
$url1 = "http://bonita.libertypr.com:8081/bonita/API/bpm/caseDocument";
$context1  = stream_context_create($options1);
$result1 = file_get_contents($url1, false, $context1);
$response1 =  json_decode($result1);

在调用此API调用之前,请确保您在Bonita端进行了身份验证。请参阅此链接了解更多详情:http://documentation.bonitasoft.com/rest-api-overview验证

如果不是,Bonita API调用将被拒绝。

为了进一步分析导致问题的原因,您应该掌握在代码和Bonita之间发送的HTTP请求和响应。为此,可以使用Wireshark

等工具捕获HTTP流量。

欢呼,