如何阻止curl php发送accept头 [英] how to stop curl php from sending accept header

查看:1042
本文介绍了如何阻止curl php发送accept头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

默认情况下,curl为所有请求发送 Accept:* / * 标头。如何停止发送默认标题?

By default curl sends Accept: */* header for all requests. How do I stop sending of the default header?

 Accept: */* 


推荐答案

传入Accept:(即冒号右侧没有内容的标题) a href =https://curl.haxx.se/libcurl/c/CURLOPT_HTTPHEADER.html> CURLOPT_HTTPHEADER 。喜欢:

Pass in "Accept:" (ie a header with no contents to the right of the colon) with CURLOPT_HTTPHEADER. Like:

$headers  =  array( "Accept:" );
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

使用curl命令行工具的效果是:

The equivalent using the curl command line tool is:

curl -H 'Accept:' http://example.com/

这将使curl 删除标题,而不只是发送一个空白的标题。如果您愿意,您也可以发送一个包含空格的标题,但是您需要使用分号而不是冒号!

This will make curl remove the header, not just send a header with a blank value. You can also send a header with a blank value if you want, but then you need to use a semicolon instead of colon!

这篇关于如何阻止curl php发送accept头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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