设置HTTP请求“内容类型” [英] Set HTTP Request "Content-Type"

查看:147
本文介绍了设置HTTP请求“内容类型”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何设置HTTP请求的内容类型?

How do you set the content type of an HTTP Request?

我尝试过:

$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

but no luck so far...
What do I have to do to get an Content-Type: application/xml in my HTTP response?

推荐答案

我相信标头必须是一个平面数组,其元素是全键:值标头,不是关联数组:

I believe the headers must be a plain array whose elements are full key:value headers, not an associative array:

$headers = array();
$headers[] = 'Accept: application/xml';
$headers[] = 'Content-Type: application/xml';

curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

这在 curl_setopt()文档

这篇关于设置HTTP请求“内容类型”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆