PHP + Curl:从multipart / form-data更改enctype

时间:2016-11-18 11:55:01

标签: php curl

curl_setopt_array($curl, array(
    CURLOPT_RETURNTRANSFER => 1,
    CURLOPT_HEADER         => false,
    CURLOPT_SSL_VERIFYHOST => 0,
    CURLOPT_SSL_VERIFYPEER => false, 
    CURLOPT_USERAGENT      => "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.36", 
    CURLOPT_TIMEOUT        => 120, 
    CURLOPT_URL => 'https://someurl.com/',
    CURLOPT_POST => 1,
    CURLOPT_POSTFIELDS => array(
                'FirstName' => $intFirstName,
                'LastName' => $intLastName,
                'Email' => $intEmail,
                'Password' => $intPassword,
                'CompanyName' => $intCompanyName,
                'PhoneNumber' => $intPhoneNumber,
                'Country' => $intCountry
    )
));

使用此功能后,我从侦听服务器获得以下响应:

{"Message":"The request entity's media type 'multipart/form-data' is not supported for this resource."}

我有什么方法可以在这里更改enctype吗?

1 个答案:

答案 0 :(得分:0)

您需要提及标题。

curl_setopt_array($curl, array(
    CURLOPT_RETURNTRANSFER => 1,
    CURLOPT_HEADER         => array("Content-Type:multipart/form-data"), // cURL headers for file uploading
    CURLOPT_SSL_VERIFYHOST => 0,
    CURLOPT_SSL_VERIFYPEER => false, 
    CURLOPT_USERAGENT      => "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.36", 
    CURLOPT_TIMEOUT        => 120, 
    CURLOPT_URL => 'https://someurl.com/',
    CURLOPT_POST => 1,
    CURLOPT_POSTFIELDS => array(
                'FirstName' => $intFirstName,
                'LastName' => $intLastName,
                'Email' => $intEmail,
                'Password' => $intPassword,
                'CompanyName' => $intCompanyName,
                'PhoneNumber' => $intPhoneNumber,
                'Country' => $intCountry
    )
));