How to set custom request header keys with curl and PHP?

后端 未结 2 557
南方客
南方客 2021-02-18 18:33

I\'m using curl and php to upload file. I need help to set a custom request header keys like

X-Filename  blahblah.zip
X-Filesize  2677
X-Filetype  application/z         


        
相关标签:
2条回答
  • 2021-02-18 19:24
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('X-Filename: blahblah.zip', 'X-Filesize: 2677', 'X-Filetype: application/zip'));
    
    0 讨论(0)
  • 2021-02-18 19:27

    You must use the curl_setopt() function, and its CURLOPT_HTTPHEADER option (quoting) :

    An array of HTTP header fields to set, in the format array('Content-type: text/plain', 'Content-length: 100')


    Basically, in your case, you'd have something like this :

    $headers = array(
        'X-Filename: blahblah.zip', 
        'X-Filesize: 2677', 
        'X-Filetype: application/zip', 
    );
    curl_setopt($your_resource, CURLOPT_HTTPHEADER, $headers);
    
    0 讨论(0)
提交回复
热议问题