Home  >  Article  >  Backend Development  >  How to solve php curl garbled problem

How to solve php curl garbled problem

藏色散人
藏色散人Original
2020-11-05 11:32:524426browse

php curl garbled solution: first open the corresponding code file; then add the statement "curl_setopt($ch, CURLOPT_ENCODING, '');" to automatically add the request header "Accept-Encoding".

How to solve php curl garbled problem

Recommended: "PHP Video Tutorial"

Solution to the problem of garbled data returned by PHP Curl

When developing in PHP, if you use curl to request a page, you may encounter garbled code problems. There are two possible reasons. One is that you passed Accept-Encoding in the request header, and the other is that the server forcibly returns gzip-compressed data.

The solution is very simple:

curl_setopt($ch, CURLOPT_ENCODING, '');

After adding this sentence, the request header Accept-Encoding will be automatically added to the request, and the returned content will be automatically decompressed and will not be garbled.

The above is the detailed content of How to solve php curl garbled problem. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn