Как заставить curl использовать протокол HTTPS
Life-Hack [Жизнь-Взлом]/ХакингЗаставляем curl использовать протокол HTTPS.
Определим используемый протокол по умолчанию, если он не указан.
Как использовать протокол HTTPS по умолчанию.
curl --silent --verbose --proto-default https --output /dev/null www.google.com * Trying 172.217.20.164:443... * Connected to www.google.com (172.217.20.164) port 443 (#0) * ALPN, offering h2 * ALPN, offering http/1.1 * successfully set certificate verify locations: * CAfile: /etc/ssl/certs/ca-certificates.crt * CApath: /etc/ssl/certs } [5 bytes data] * TLSv1.3 (OUT), TLS handshake, Client hello (1): } [512 bytes data] * TLSv1.3 (IN), TLS handshake, Server hello (2): { [122 bytes data] * TLSv1.3 (IN), TLS handshake, Encrypted Extensions (8): { [15 bytes data] * TLSv1.3 (IN), TLS handshake, Certificate (11): { [4002 bytes data] * TLSv1.3 (IN), TLS handshake, CERT verify (15): { [78 bytes data] * TLSv1.3 (IN), TLS handshake, Finished (20): { [52 bytes data] * TLSv1.3 (OUT), TLS change cipher, Change cipher spec (1): } [1 bytes data] * TLSv1.3 (OUT), TLS handshake, Finished (20): } [52 bytes data]
Обратите внимание, что эта опция не будет иметь смысла, если указан протокол.
curl --silent --verbose --proto-default https --output /dev/null http://www.google.com * Trying 172.217.20.164:80... * Connected to www.google.com (172.217.20.164) port 80 (#0) > GET / HTTP/1.1 > Host: www.google.com > User-Agent: curl/7.74.0 > Accept: */* > * Mark bundle as not supporting multiuse < HTTP/1.1 200 OK < Date: Sun, 03 Apr 2022 14:13:35 GMT < Expires: -1 < Cache-Control: private, max-age=0 < Content-Type: text/html; charset=ISO-8859-1 < P3P: CP="This is not a P3P policy! See g.co/p3phelp for more info." < Server: gws < X-XSS-Protection: 0 < X-Frame-Options: SAMEORIGIN < Set-Cookie: AEC=AVQQ_LB3ZtfdU4cku43U7Qdo_c-ZwIuO45QgAWklIJhrePMbwGxssu7n8A; expires=Fri, 30-Sep-2022 14:13:35 GMT; path=/; domain=.google.com; Secure; HttpOnly; SameSite=lax < Set-Cookie: NID=511=nOfnqUz31txzRl-4e2lRB0PRVFywR16dmxdDhym-xJo1Dgiau5z2b1WfeC9ZiC8YBg2C6GhTjm8gEEu30VrYLaMURv6hV0e5jxI4kJaGweWtEhkz1Si4RN6ae0VHusVWMdMgF_U1EAMVJdUAfK3mpIIZX4oqTV4uoKAbdo3KZtY; expires=Mon, 03-Oct-2022 14:13:35 GMT; path=/; domain=.google.com; HttpOnly < Accept-Ranges: none < Vary: Accept-Encoding < Transfer-Encoding: chunked < { [6292 bytes data] * Connection #0 to host www.google.com left intact
Обратите внимание, что эта опция не будет иметь смысла, если указан протокол.
curl --silent --verbose --proto-default https --output /dev/null http://www.google.com * Trying 172.217.20.164:80... * Connected to www.google.com (172.217.20.164) port 80 (#0) > GET / HTTP/1.1 > Host: www.google.com > User-Agent: curl/7.74.0 > Accept: */* > * Mark bundle as not supporting multiuse < HTTP/1.1 200 OK < Date: Sun, 03 Apr 2022 14:13:35 GMT < Expires: -1 < Cache-Control: private, max-age=0 < Content-Type: text/html; charset=ISO-8859-1 < P3P: CP="This is not a P3P policy! See g.co/p3phelp for more info." < Server: gws < X-XSS-Protection: 0 < X-Frame-Options: SAMEORIGIN < Set-Cookie: AEC=AVQQ_LB3ZtfdU4cku43U7Qdo_c-ZwIuO45QgAWklIJhrePMbwGxssu7n8A; expires=Fri, 30-Sep-2022 14:13:35 GMT; path=/; domain=.google.com; Secure; HttpOnly; SameSite=lax < Set-Cookie: NID=511=nOfnqUz31txzRl-4e2lRB0PRVFywR16dmxdDhym-xJo1Dgiau5z2b1WfeC9ZiC8YBg2C6GhTjm8gEEu30VrYLaMURv6hV0e5jxI4kJaGweWtEhkz1Si4RN6ae0VHusVWMdMgF_U1EAMVJdUAfK3mpIIZX4oqTV4uoKAbdo3KZtY; expires=Mon, 03-Oct-2022 14:13:35 GMT; path=/; domain=.google.com; HttpOnly < Accept-Ranges: none < Vary: Accept-Encoding < Transfer-Encoding: chunked < { [6292 bytes data] * Connection #0 to host www.google.com left intact
Применим протокол HTTPS, но пытаемся использовать другой протокол.
curl --silent --verbose --proto-default https --proto =https --output /dev/null http://google.com * Protocol "http" not supported or disabled in libcurl * Closing connection -1
Определим принятый протокол для назначения перенаправления
Применим протокол HTTPS для назначения перенаправления.
curl --location --silent --verbose --proto-redir =https --o
Применим протокол HTTPS для назначения перенаправления, но попробуем использовать протокол HTTP.
curl --location --silent --verbose --proto-redir =https --output /dev/null http://google.com * Trying 216.58.209.14:80... * Connected to google.com (216.58.209.14) port 80 (#0) > GET / HTTP/1.1 > Host: google.com > User-Agent: curl/7.74.0 > Accept: */* > * Mark bundle as not supporting multiuse < HTTP/1.1 301 Moved Permanently < Location: http://www.google.com/ < Content-Type: text/html; charset=UTF-8 < Date: Sun, 03 Apr 2022 14:19:11 GMT < Expires: Tue, 03 May 2022 14:19:11 GMT < Cache-Control: public, max-age=2592000 < Server: gws < Content-Length: 219 < X-XSS-Protection: 0 < X-Frame-Options: SAMEORIGIN < * Ignoring the response-body { [219 bytes data] * Connection #0 to host google.com left intact * Issue another request to this URL: 'http://www.google.com/' * Protocol "http" not supported or disabled in libcurl * Closing connection -1
Прочитайте страницу руководства curl для более подробной информации и просто объедините эти опции вместе.