This commit is contained in:
Romain Vincent 2026-03-01 03:35:12 -08:00 committed by GitHub
commit 407525faa6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -169,7 +169,7 @@ Form encoded data can also include multiple values from a given key.
}
```
## Sending Multipart File Uploads
## Sending Multipart File Uploads and/or Data
You can also upload files, using HTTP multipart encoding:
@ -224,6 +224,23 @@ If you need to include non-file data fields in the multipart form, use the `data
}
```
If you need to send non-file data only, you can do so by using a tuple
of items for the field value without a filename:
```pycon
>>> files = {'some-field': (None, "field-value")}
>>> r = httpx.post("https://httpbin.org/post", files=files)
>>> print(r.text)
{
...
"files": {},
"form": {
"some-field": "field-value"
},
...
}
```
## Sending JSON Encoded Data
Form encoded data is okay if all you need is a simple key-value data structure.