服务器通信-传输文件

时间:2020-06-04 14:42:37

标签: node.js laravel file http curl

我正在使用Laravel构建项目,我需要开始一个很大的安装过程。 该过程的一小部分是将POST请求发送到另一个Node.js服务器,该服务器包括:

{
  file: (file from server storage),
  uuid: "2342134-21321-321-3213",
  name: 'test'
}

我想为此使用cURL。 这是代码:

    $file_to_send = '@/' . storage_path() . "/app/tmp/" . $file_path;
    $data_to_send = array(
      "podp" => $file_to_send,
      "uuid" => self::$data['serial_id'],
      "name" => self::$data['name'],  
    );
    $headers = [
      'Content-Type: multipart/form-data'
    ];

    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, 'https://test.com/test');
    curl_setopt($curl, CURLOPT_TIMEOUT, 60);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
    curl_setopt($curl, CURLOPT_POST, 1);
    curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data_to_send));
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
    $result = curl_exec($curl);

它没有用。 我也曾尝试为此使用CURLFile Class,但是另一台服务器获得了“文件”属性的完整路径。

$file_to_send =new CURLFile(storage_path() . "/app/tmp/" . $file_path);

请帮助:-)

0 个答案:

没有答案
相关问题