不要在cURL中发送任何Content-type标头 [英] Do not send any Content-type header in cURL

查看:1905
本文介绍了不要在cURL中发送任何Content-type标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将我的cURL请求的内容类型头设置为null。
由于某种原因,我试图使用的API,不允许Content-Type。
如果我给一个内容类型我得到一个415响应。

I'm trying to set the content-type header of my cURL request to null. For some reason the API I'm trying to use, does not allow a Content-Type. If I do give a content-type I get a 415 Response.

但是似乎cURL总是发送一个Content-Type。

But it seems that cURL always sents a Content-Type. even if I don't set one.

我尝试过:

curl_setopt($request, CURLOPT_HTTPHEADER, array());

curl_setopt($request, CURLOPT_HTTPHEADER, array(
    'Content-type: null'));

curl_setopt($request, CURLOPT_HTTPHEADER, array(
    'Content-type: ""',

));

但无效。

谢谢!

推荐答案

不发送内容类型头的cURL请求。这是简短的答案。
这是不可能的。

Ok, so you can't send a cURL request without a content-type header. That is the short answer. It's just not possible.

如果你不设置它自己,它会将内容类型设置为

If you do not set it your self, it will set the content-type to

text/html

发送文件。最后发现内容类型,对于这个特定的API,应该设置为:

I was trying to send a file. And finally found that the content-type, for this specific API, should be set to:

application/octet-stream

这篇关于不要在cURL中发送任何Content-type标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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