Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Leer Challenge: Check Website Web Protocol | Web Cyber Security
Cyber Security Fundamentals

book
Challenge: Check Website Web Protocol

Taak

Swipe to start coding

Let's create a simple function that will make a basic request to a website and check whether it uses HTTPS.
Your task is to:

  1. Make a request and check if the response status code equals 200. It's needed to check the availability of the chosen URL.
  2. Check if the response URL starts with subscring https. It will indicate that our source uses HTTPS web protocol.
  3. Call the check_https_protocol() function with the corresponding URL as an argument to check it.

Note

While our URL ('http://codefinity.com') initially indicates the use of the HTTP protocol, the server might redirect it to HTTPS as per its server-side configurations. We aim to ascertain the server's support for HTTPS by examining its configurations. If successful, our request will be redirected, and the response URL will commence with 'https'.

Oplossing

import requests # Import the requests library for making HTTP requests

def check_https_protocol(url):
try:
# Send an HTTP GET request to the specified URL
response = requests.get(url)
# Check if the response status code is 200 (OK)
if response.status_code == 200:
# Check if the URL starts with 'https'
if response.url.startswith('https'):
return f'The website {url} uses HTTPS. It is secure.'
else:
return f'The website {url} does not use HTTPS. It is not secure.'
else:
# If the response status code is not 200, return an error message
return f'Error: Unable to connect to {url}.'
except requests.exceptions.RequestException as e:
# Handle any exceptions that may occur during the request (e.g., network issues)
return f'Error: {e}'

# Example usage:
url_to_check = 'http://codefinity.com'
result = check_https_protocol(url_to_check)
print(result)

Was alles duidelijk?

Hoe kunnen we het verbeteren?

Bedankt voor je feedback!

Sectie 2. Hoofdstuk 3
import requests # Import the `requests` library for making HTTP requests

def check_https_protocol(url):
try:
# Send an HTTP GET request to the specified URL
response = requests.get(url)
# Check if the response status code is 200 (OK)
if response.status_code == ___:
# Check if the URL starts with 'https'
if response.url.startswith('___'):
return f'The website {url} uses HTTPS. It is secure.'
else:
return f'The website {url} does not use HTTPS. It is not secure.'
else:
# If the response status code is not 200, return an error message
return f'Error: Unable to connect to {url}.'
except requests.exceptions.RequestException as e:
# Handle any exceptions that may occur during the request (e.g., network issues)
return f'Error: {e}'

# Example usage:
url_to_check = 'http://codefinity.com'
result = ___(url_to_check)
print(result)

Vraag AI

expand
ChatGPT

Vraag wat u wilt of probeer een van de voorgestelde vragen om onze chat te starten.

some-alt