Troubleshooting of curl errors: Difference between revisions

From LemonWiki共筆
Jump to navigation Jump to search
No edit summary
Line 41: Line 41:
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: Check the API documentation which HTTP request method<ref>[https://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html HTTP/1.1: Method Definitions]</ref> is the correct e.g. {{kbd | key=GET}} or {{kbd | key=POST}}
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 ==

Revision as of 19:13, 29 May 2020

cUrl "is used in command lines or scripts to transfer data."[1] (alternative library to achive sampe purpose: (1) PHP naive Client URL Library (2) cURL class for PHP (3) Installing cURL on Cygwin on Windows)

How to resolve cUrl error (#5): Unsupported proxy syntax

Condition: the username of socks5 proxy contains @ symbol such as [email protected]

curl_setopt($ch, CURLOPT_PROXY, 'socks5://username:password@localhost:12345');
// result is ok

curl_setopt($ch, CURLOPT_PROXY, 'socks5://[email protected]:password@localhost:12345');
// met cUrl error (#5): Unsupported proxy syntax

Solution: Escape the special symbol[1] using URL Encode and Decode - Online or urlencode function

curl_setopt($ch, CURLOPT_PROXY, 'socks5://bob%40email.com:password@localhost:12345');
// result is ok

How to resolve cUrl error (#56): OpenSSL SSL_read: No error.

Condition: The curl vesion 7.67.0 on windows met problem. Result of curl_version returned:

version: Array
(
    [version_number] => 475904
    [age] => 5
    [features] => 2953117
    [ssl_version_number] => 0
    [version] => 7.67.0
    [host] => x86_64-pc-win32
    [ssl_version] => OpenSSL/1.1.1d
    [libz_version] => 1.2.11
)

Solution: Use other version of curl command or curl on Cygwin or cURL class for PHP.

Related articles

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"

Solution: Make sure using the correct HTTP request method[2] e.g. GET or POST to access the web resource.

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"

Solution: Set the cUrl with the header Content-Type: application/json[3]

curl -X POST --header "Content-Type: application/json" --data '{"user" : "your_user_name", "token" : "your_token"}' "https://example.com/"

References


Troubleshooting of ...

Template