python
neu = {'title': 'Hallo', 'body': 'Testbeitrag', 'userId': 1}
r = httpx.post('https://jsonplaceholder.typicode.com/posts', json=neu, timeout=10)
print(r.status_code, r.json()) # 201 und der angelegte Datensatz mit 'id'
httpx.put(url, json=vollstaendig)
httpx.patch(url, json={'title': 'Neu'})
httpx.delete(url)
| Parameter | Wann |
|---|---|
json= |
Dictionary wird als JSON gesendet, Content-Type setzt httpx selbst |
data= |
Formulardaten (application/x-www-form-urlencoded) |
files= |
Datei-Upload, z. B. {'datei': open('a.pdf', 'rb')} |
content= |
Rohe Bytes oder Text |