Home > Article > Backend Development > How to solve php curl garbled problem
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".
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!