Skip to content

Commit

Permalink
Update Python-basics.md
Browse files Browse the repository at this point in the history
  • Loading branch information
Aif4thah committed Oct 30, 2024
1 parent b3d8607 commit cafd272
Showing 1 changed file with 49 additions and 1 deletion.
50 changes: 49 additions & 1 deletion Dojo-101-DevSec/Python-basics.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ urllib.parse.quote('&')
#'%26'
```

## http client:
## http.client:

```python
import http.client
Expand All @@ -227,6 +227,54 @@ conn = http.client.HTTPSConnection('enirdd6d0146.x.pipedream.net')
conn.request("POST", "/", '{ "name": "Princess Leia" }', {'Content-Type': 'application/json'})
```

## Request

### GET

```python
import requests

base_url = "https://localhost:3000"
url = f"{base_url}/?lang=english"
token = "ey...................."

headers = {
"Authorization": f"Bearer {token}"
}

response = requests.get(url, headers=headers, verify=False)

# Vérification des conditions de correspondance
if response.status_code == 200 and ("success" in response.text or "16-bit" in response.text):
print("Condition matched: success or 16-bit found and status is 200")
else:
print(f"Received status code: {response.status_code} with no matching content")
```


### POST

```python
import requests

url = "http://localhost:4000/Login"
payload = {
"user": "user",
"passwd": "password"
}
headers = {
"Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

if response.status_code == 401:
print("Unauthorized access - status code 401")
else:
print(f"Received status code: {response.status_code}")
```


## request + BeautifulSoup

### POST
Expand Down

0 comments on commit cafd272

Please sign in to comment.