Gru*_*uck 8 php curl stream http-put
我一直在努力争取如何完成这项工作几个小时.我正在尝试通过HTTP-PUT将文件发送到eXist数据库.有服务器的用户身份验证,所以我试图做这样的事情:
我有要将文档输入的URL我有eXist DB的用户名和密码我有需要通过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);
啊哈!在我的桌子上有一个脾气暴躁的矮人毛绒娃娃的"橡皮鸭"之后,我想出了解决方案:
$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 == '');