加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php – 设置HTTP请求“内容类型”

发布时间:2020-12-13 13:49:19 所属栏目:PHP教程 来源:网络整理
导读:如何设置HTTP请求的内容类型? 我试过这个: $headers['Accept'] = 'application/xml';$headers['Content-Type'] = 'application/xml';curl_setopt($ch,CURLOPT_HTTPHEADER,$headers); 这就是结果: HTTP/1.1 200 OKContent-Encoding: gzipContent-Type: tex
如何设置HTTP请求的内容类型?

我试过这个:

$headers['Accept'] = 'application/xml';
$headers['Content-Type'] = 'application/xml';

curl_setopt($ch,CURLOPT_HTTPHEADER,$headers);

这就是结果:

HTTP/1.1 200 OK
Content-Encoding: gzip
Content-Type: text/html;charset=UTF-8
Date: Thu,22 Mar 2012 14:04:36 GMT

但到目前为止没有运气……
在HTTP响应中获取Content-Type:application / xml需要做什么?

我相信标题必须是一个普通的数组,其元素是完整的键:值标题,而不是关联数组:
$headers = array();
$headers[] = 'Accept: application/xml';
$headers[] = 'Content-Type: application/xml';

curl_setopt($ch,$headers);

这在curl_setopt() documentation.中指定

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读