对于请求'POST / api / v1 / images'[缺少边界标头]

时间:2018-10-06 05:54:33

标签: php curl

我正在尝试使用php中的curl将文件和字符串发布到url,但是它显示以下错误:

  

对于请求'POST / api / v1 / images'[缺少边界标头]

以下是我的代码

if(isset($_POST['imageupload'])){
    $headers = array(
        'Accept' => 'application/json',
            'Authorization'=>'Basic NjU0MDo4sdgdsfsdfsdfdssdfdssdfdsfMGt1NDk4c3Vi'
        );
    $username='654sldjfl0';
        $password='8dfljgfldjgdfjgfdl80ku498sub';
    $test ="true";
        $ch = curl_init();
    $ch = curl_init();
        $data = array('image' => curl_file_create($_FILES["image"]["tmp_name"], $_FILES['image']['type'], $_FILES['image']['name']),'test' => 'true');             
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_URL, 'somehttpsurl');
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($ch, CURLOPT_HEADER, 1);
    curl_setopt($ch, CURLOPT_USERPWD, "sugumar" . ":" . "123456");
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    curl_setopt($ch, CURLOPT_POST, 1);



    $server_output = curl_exec($ch);

    curl_close ($ch);
    if (curl_error($ch)) {
        $error_msg = curl_error($ch);
        echo $error_msg;
    }
    print_r($server_output);
}

我尚未设置Content-Type:multipart / form-data,因为我读取了带有数组值的postfield设置了标头

0 个答案:

没有答案