The boundary in the Content-Type header of a multipart/form-data request is a unique string that acts as a delimiter between the different parts of the multipart message. When you make a POST request directly from a browser using a form, the browser automatically generates this boundary, and as you've noticed, browsers like those based on WebKit (e.g., Chrome, Safari) include the phrase WebKitFormBoundary followed by a string in their boundary definitions.
When using Python, particularly libraries such as requests to generate a multipart/form-data request, the boundary is generated differently, without the WebKitFormBoundary prefix, leading to the observed difference.
If for some reason you need your Python requests to closely mimic browser requests, including having a similar-looking boundary, you can manually construct your multipart/form-data body and headers. However, be aware that manually crafting such requests can be complex and is generally unnecessary unless you have a very specific requirement, such as trying to bypass some simplistic form of request validation on the server-side (which would likely be a sign of poor server-side validation practices).
Below is an example using the requests library where you manually create a multipart/form-data body with a boundary that mimics a browser's:
import requests
# Your custom boundary that mimics a WebKitFormBoundary
boundary = '----WebKitFormBoundaryuByUcQTsAuAyNFOd'
headers = {
'Content-Type': 'multipart/form-data; boundary={}'.format(boundary),
}
# Manually construct the body of the multipart/form-data request
data = '--{}\r\n'.format(boundary)
data += 'Content-Disposition: form-data; name="field1"\r\n\r\n'
data += 'value1\r\n'
data += '--{}\r\n'.format(boundary)
data += 'Content-Disposition: form-data; name="field2"; filename="example.txt"\r\n'
data += 'Content-Type: text/plain\r\n\r\n'
data += 'File content goes here.\r\n'
data += '--{}--\r\n'.format(boundary)
response = requests.post('http://example.com/', headers=headers, data=data)
print(response.text)
Note: Make sure that the boundary string you use does not accidentally appear in the content of the fields or files you're transmitting, as it's meant to be a unique delimiter. In practice, web servers and applications should not behave differently based on the presence of specific text in the boundary, so needing to do this is rare.
Also, remember that the requests library (and other HTTP client libraries in Python) are designed to abstract away these kinds of low-level details. If you're just trying to send multipart/form-data requests without specific requirements on the boundary format, letting the library handle it for you is the simplest and most robust approach.