14,958
edits
No edit summary |
|||
| Line 6: | Line 6: | ||
== How to resolve Command Execution: Works in DOS/Terminal but Not in PHP == | == List of curl errors == | ||
=== How to resolve Command Execution: Works in DOS/Terminal but Not in PHP === | |||
Often, commands that run perfectly when manually executed in DOS or the Windows terminal (like [https://conemu.github.io/ ConEmu]) might not produce the expected outcome when run through PHP. A common issue is the command not generating the anticipated file. | Often, commands that run perfectly when manually executed in DOS or the Windows terminal (like [https://conemu.github.io/ ConEmu]) might not produce the expected outcome when run through PHP. A common issue is the command not generating the anticipated file. | ||
| Line 27: | Line 28: | ||
</pre> | </pre> | ||
== How to resolve cURL Binary Output Warning == | === How to resolve cURL Binary Output Warning === | ||
When executing a cURL command, you might encounter this warning message: | When executing a cURL command, you might encounter this warning message: | ||
| Line 45: | Line 46: | ||
</pre> | </pre> | ||
== How to resolve cURL error: HTTP/2 stream 0 was not closed cleanly: PROTOCOL_ERROR (err 1) == | === How to resolve cURL error: HTTP/2 stream 0 was not closed cleanly: PROTOCOL_ERROR (err 1) === | ||
Workaround solution<ref>[https://stackoverflow.com/questions/56865217/php-curl-error-http-2-stream-0-was-not-closed-cleanly-protocol-error-err-1 PHP Curl error HTTP/2 stream 0 was not closed cleanly: PROTOCOL_ERROR (err 1) - Stack Overflow]</ref>: | Workaround solution<ref>[https://stackoverflow.com/questions/56865217/php-curl-error-http-2-stream-0-was-not-closed-cleanly-protocol-error-err-1 PHP Curl error HTTP/2 stream 0 was not closed cleanly: PROTOCOL_ERROR (err 1) - Stack Overflow]</ref>: | ||
<pre> | <pre> | ||
| Line 51: | Line 52: | ||
</pre> | </pre> | ||
== How to resolve cUrl error (3) bad range in URL position xx == | === How to resolve cUrl error (3) bad range in URL position xx === | ||
'''Problem''' | '''Problem''' | ||
| Line 82: | Line 83: | ||
If you're unsure whether encoding is needed, you can use an online URL encoder tool for conversion e.g. [https://www.urlencoder.org/ URL Encode and Decode - Online]. | If you're unsure whether encoding is needed, you can use an online URL encoder tool for conversion e.g. [https://www.urlencoder.org/ URL Encode and Decode - Online]. | ||
== How to resolve cUrl error (#5): Unsupported proxy syntax == | === How to resolve cUrl error (#5): Unsupported proxy syntax === | ||
Condition: the username of [https://en.wikipedia.org/wiki/SOCKS socks5 proxy] contains @ symbol such as {{kbd | key=<nowiki>[email protected]</nowiki>}} | Condition: the username of [https://en.wikipedia.org/wiki/SOCKS socks5 proxy] contains @ symbol such as {{kbd | key=<nowiki>[email protected]</nowiki>}} | ||
<pre> | <pre> | ||
| Line 98: | Line 99: | ||
</pre> | </pre> | ||
== How to resolve cUrl error (#56): OpenSSL SSL_read: No error. == | === How to resolve cUrl error (#56): OpenSSL SSL_read: No error. === | ||
Condition: The curl vesion 7.67.0 on windows met problem. Result of [https://www.php.net/manual/en/function.curl-version.php curl_version] returned: | Condition: The curl vesion 7.67.0 on windows met problem. Result of [https://www.php.net/manual/en/function.curl-version.php curl_version] returned: | ||
<pre> | <pre> | ||
| Line 119: | Line 120: | ||
* [https://github.com/curl/curl/issues/4982 cURL error 56: OpenSSL SSL_read: No error information · Issue #4982 · curl/curl] | * [https://github.com/curl/curl/issues/4982 cURL error 56: OpenSSL SSL_read: No error information · Issue #4982 · curl/curl] | ||
== How to resolve cURL error: SSL: no alternative certificate subject name matches target host name xxx == | === How to resolve cURL error: SSL: no alternative certificate subject name matches target host name xxx === | ||
Walkaround solution<ref>[https://stackoverflow.com/questions/20842970/curl-fix-curl-51-ssl-error-no-alternative-certificate-subject-name-matches Curl: Fix CURL (51) SSL error: no alternative certificate subject name matches - Stack Overflow]</ref>: | Walkaround solution<ref>[https://stackoverflow.com/questions/20842970/curl-fix-curl-51-ssl-error-no-alternative-certificate-subject-name-matches Curl: Fix CURL (51) SSL error: no alternative certificate subject name matches - Stack Overflow]</ref>: | ||
| Line 127: | Line 128: | ||
</pre> | </pre> | ||
== How to resolve the error: error code: 1010 == | === How to resolve the error: error code: 1010 === | ||
Identifying the Issue | Identifying the Issue | ||
| Line 141: | Line 142: | ||
* Instead of relying on the cURL command, switching to a JavaScript-based crawler is recommended as a solution to this problem <ref>[https://www.zenrows.com/blog/cloudflare-error-1010#how-to-avoid Cloudflare Error 1010: What Is It and How to Avoid - ZenRows]</ref>. | * Instead of relying on the cURL command, switching to a JavaScript-based crawler is recommended as a solution to this problem <ref>[https://www.zenrows.com/blog/cloudflare-error-1010#how-to-avoid Cloudflare Error 1010: What Is It and How to Avoid - ZenRows]</ref>. | ||
== How to resolve 400 Bad Request Errors: UTF-8 Character Encoding Issues == | === How to resolve 400 Bad Request Errors: UTF-8 Character Encoding Issues === | ||
'''Problem Analysis:''' | '''Problem Analysis:''' | ||
| Line 173: | Line 174: | ||
</pre> | </pre> | ||
== How to resolve Error 405 Method Not Allowed == | === How to resolve Error 405 Method Not Allowed === | ||
When I tried to crawl the web resource but met the error message: "Error 405 Method Not Allowed" | When I tried to crawl the web resource but met the error message: "Error 405 Method Not Allowed" | ||
Solution: Make sure using the correct HTTP request method<ref>[https://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html HTTP/1.1: Method Definitions]</ref> e.g. {{kbd | key=GET}} or {{kbd | key=POST}} to access the web resource. | Solution: Make sure using the correct HTTP request method<ref>[https://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html HTTP/1.1: Method Definitions]</ref> e.g. {{kbd | key=GET}} or {{kbd | key=POST}} to access the web resource. | ||
== How to resolve Error 415 Unsupported Media Type == | === How to resolve Error 415 Unsupported Media Type === | ||
When I tried to POST JSON (as payload) but met the error message: "Error 415 Unsupported Media Type" | When I tried to POST JSON (as payload) but met the error message: "Error 415 Unsupported Media Type" | ||
| Line 187: | Line 188: | ||
</pre> | </pre> | ||
== How to rseolve cURL returns binary data instead of html or json == | === How to rseolve cURL returns binary data instead of html or json === | ||
* [https://stackoverflow.com/questions/28283822/curl-returns-binary-data-instead-of-html php - cURL returns binary data instead of html - Stack Overflow] | * [https://stackoverflow.com/questions/28283822/curl-returns-binary-data-instead-of-html php - cURL returns binary data instead of html - Stack Overflow] | ||
* [https://errerrors.blogspot.com/2020/06/resolve-curl-returns-binary-data-instead-of-html-or-json.html 解決 cUrl 下載的網頁或 JSON 看起來像是亂碼的問題] | * [https://errerrors.blogspot.com/2020/06/resolve-curl-returns-binary-data-instead-of-html-or-json.html 解決 cUrl 下載的網頁或 JSON 看起來像是亂碼的問題] | ||
== How to resolve the downloaded file was empty == | === How to resolve the downloaded file was empty === | ||
Error condition | Error condition | ||
* When I executed the Curl command {{kbd | key=<nowiki>curl -O https://path/to/plain_text.txt</nowiki>}}, but the downloaded file was empty. | * When I executed the Curl command {{kbd | key=<nowiki>curl -O https://path/to/plain_text.txt</nowiki>}}, but the downloaded file was empty. | ||
| Line 212: | Line 213: | ||
</pre> | </pre> | ||
== How to resolve the error: no matches found == | === How to resolve the error: no matches found === | ||
'''Error condition''' | '''Error condition''' | ||
* When I executed the Curl command {{kbd | key=<nowiki>curl http://website.test/http_status.php?case=500</nowiki>}}, but I met the error message: "zsh: no matches found: <nowiki>http://website.test/http_status.php?case=500</nowiki>" | * When I executed the Curl command {{kbd | key=<nowiki>curl http://website.test/http_status.php?case=500</nowiki>}}, but I met the error message: "zsh: no matches found: <nowiki>http://website.test/http_status.php?case=500</nowiki>" | ||
| Line 238: | Line 239: | ||
</div> | </div> | ||
== How to resolve the error: Remote file name has no length == | === How to resolve the error: Remote file name has no length === | ||
Error message | Error message | ||
| Line 255: | Line 256: | ||
* When you encounter an error while downloading a file with `curl`, it may be because the URL does not include a file name, causing `curl` to be unable to determine the name to save the file under. The solution is to manually specify a file name using the `-o` option, for example, `curl -o myfile.html "https://website.com/?p=123"`. Additionally, make sure you have enough disk space and are in a directory where you have write permissions. | * When you encounter an error while downloading a file with `curl`, it may be because the URL does not include a file name, causing `curl` to be unable to determine the name to save the file under. The solution is to manually specify a file name using the `-o` option, for example, `curl -o myfile.html "https://website.com/?p=123"`. Additionally, make sure you have enough disk space and are in a directory where you have write permissions. | ||
== How to resolve the error: zsh: parse error near `&' == | === How to resolve the error: zsh: parse error near `&' === | ||
Error condition | Error condition | ||
<pre> | <pre> | ||
| Line 273: | Line 274: | ||
</pre> | </pre> | ||
== How to Suppress the Progress Meter == | === How to Suppress the Progress Meter === | ||
When executing the curl command, the typical output includes detailed information about the download and upload process as shown below: | When executing the curl command, the typical output includes detailed information about the download and upload process as shown below: | ||
<pre> | <pre> | ||
| Line 292: | Line 293: | ||
== How to resolve cURL Illegal Filename Character Error == | === How to resolve cURL Illegal Filename Character Error === | ||
When executing a cURL command with illegal characters in the output filename, you might encounter this error message: | When executing a cURL command with illegal characters in the output filename, you might encounter this error message: | ||
| Line 309: | Line 310: | ||
* Create directories first if needed: {{kbd | key=<nowiki>mkdir -p directory</nowiki>}} | * Create directories first if needed: {{kbd | key=<nowiki>mkdir -p directory</nowiki>}} | ||
== cURL JSON Payload Issues in Windows vs Mac/Linux Systems == | === cURL JSON Payload Issues in Windows vs Mac/Linux Systems === | ||
'''1. Problem''' | '''1. Problem''' | ||
| Line 330: | Line 331: | ||
PHP code: | PHP code: | ||
<pre> | <pre> | ||
$is_windows = strtoupper(substr(PHP_OS, 0, 3)) === 'WIN'; | $is_windows = strtoupper(substr(PHP_OS, 0, 3)) ===== 'WIN'; | ||
if ($is_windows) { | if ($is_windows) { | ||
$command = sprintf('-d "{\"key\":\"%s\"}"', $value); | $command = sprintf('-d "{\"key\":\"%s\"}"', $value); | ||
| Line 356: | Line 357: | ||
<references /> | <references /> | ||
{{Template:Troubleshooting}} | {{Template: Troubleshooting}} | ||
[[Category: Web server]] [[Category: Programming]] [[Category: Web scraping]] [[Category: Revised with LLMs]] | [[Category: Web server]] [[Category: Programming]] [[Category: Web scraping]] [[Category: Revised with LLMs]] | ||