我已经苦苦挣扎了几个小时,试图弄清楚如何完成这项工作。我正在尝试通过 HTTP-PUT 将文件发送到 eXist 数据库。服务器有用户身份验证,所以我试图做这样的事情:
我有文档要放置到的 URL 我有 eXist 数据库的用户名和密码 我有需要通过 PUT 发送的内容
我试着开始使用 cURL,但它会默默地失败 我尝试使用 PHP 流,但一直收到“错误 201/已创建”,但实际并未创建任何文件。
如有任何帮助,我们将不胜感激。
这是我尝试使用 PHP 流的一些示例代码
$data = file_get_contents($tmpFile); $header = array( "Authorization: Basic " . base64_encode($this->ci->config->item('ws_login') . ':' . $this->ci->config->item('ws_passwd')), "Content-Type: text/xml" ); $params = array( 'http' => array( 'method' => 'PUT', 'header' => $header, 'content' => $data)); $ctx = stream_context_create($params); $response = file_get_contents($url, false, $ctx);
最佳答案
啊哈!在与我 table 上脾气暴躁的矮人毛绒玩偶进行了一次“橡皮鸭”游戏之后,我找到了解决方案:
$data = file_get_contents($tmpFile); $params = array( 'http' => array( 'method' => 'PUT', 'header' => "Authorization: Basic " . base64_encode($this->ci->config->item('ws_login') . ':' . $this->ci->config->item('ws_passwd')) . "\r\nContent-type: text/xml\r\n", 'content' => file_get_contents($tmpFile) ) ); $ctx = stream_context_create($params); $response = @file_get_contents($url, false, $ctx); return ($response == '');
关于php - 在 PHP 中通过 HTTP PUT 发送文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1691530/