如何使用curl和PHP设置自定义请求标头键? [英] How to set custom request header keys with curl and PHP?
本文介绍了如何使用curl和PHP设置自定义请求标头键?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用curl和php上传文件。我需要帮助来设置自定义请求标头键,例如
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/zip
推荐答案
使用 curl_setopt()
函数及其 CURLOPT_HTTPHEADER
选项(引用):
You must use the curl_setopt()
function, and its CURLOPT_HTTPHEADER
option (quoting) :
要设置的HTTP标头字段数组,格式为
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);
这篇关于如何使用curl和PHP设置自定义请求标头键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文