file_get_contents(): Content-type not specified assuming application/x-www-form-urlencoded

PHP与SEO 思享 741浏览

最近用粗糙的代码给采集写了几个数据处理的函数,虽然功能能够正常实现,但是却产生了大量的报错日志,如果一天不清理几十个G就占满了,今天筛查打算解决这个问题

报错信息

file_get_contents(): Content-type not specified assuming application/x-www-form-urlencoded

百度翻译一下大体能看明白,意思是说file_get_contents()函数post数据的时候客户端Content-type标头没有设置application/x-www-form-urlencoded

于是我自己就人工访问页面然后抓包,获取的标头信息是

Content-Type: application/x-www-form-urlencoded; charset=UTF-8

在header中加入以上标头信息问题成功解决

备注:有的Content-Type标头后面没有charset=UTF-8,大家以自己实际的标头为准

推荐阅读

Function get_magic_quotes_gpc() is deprecated报错解决办法

在 PHP 7.4 及更高版本中, get_magic_quotes_gpc() 函数已被弃用。 This means that code using this function will raise a warning or error.以下是解决......

PHP提示:Warning: count():Parameter must be an array or an object that implements Countable

错误原因:PHP7.2以后,count()函数的参数无效时会抛出warning警告。...

PHP7.4 报错:Deprecated Functionality: implode(): Passing glue string after array is deprecated.

PHP7.4运行项目报错:Deprecated Functionality: implode(): Passing glue string after array is deprecated。只需交换 implode() 函数的两个参数!...