Sending files in curl request with header application
I am trying to send data in json format in curl request. so my body is like this
$body = json_encode($array);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($body),
'Content-Md5: ' . base64_encode(md5($body, true))
));
I can set content header this way --header "Content-Type: application/json" But when my content body will have files to be sent, will content type header application/json work? Do i need to change the content-type header if my body has file in it?
No and yes, if you are talking about simulating a browser to "select" files and "upload" them to the server then the header will change to
Content-Type: multipart/form-data;
if on the other hand you are talking about using text files in place of long strings on the command line then no. Read the notes in the answers at send/post xml file using curl command line
链接地址: http://www.djcxy.com/p/48906.html上一篇: CURL修改请求标头
下一篇: 使用头部应用程序发送curl请求中的文件