lexiforest / curl_cffi

Python binding for curl-impersonate fork via cffi. A http client that can impersonate browser tls/ja3/http2 fingerprints.
https://curl-cffi.readthedocs.io/
MIT License
2.49k stars 265 forks source link

Clarification Needed on How to Send JSON Data in Multipart Requests with curl_cffi #404

Closed TheRealStingo closed 1 month ago

TheRealStingo commented 1 month ago

Description: I am currently working with the curl_cffi library and need to send JSON data as part of a multipart request. Specifically, I am looking for guidance on how to correctly send JSON data in a multipart form without using files.

Here is an example of the multipart form data I need to send:

------WebKitFormBoundarywF2oYBwsfEq6mIWK
Content-Disposition: form-data; name="bookerChoicesJson"

{"insurance":{}}
------WebKitFormBoundarywF2oYBwsfEq6mIWK--

However, I have not been able to find clear documentation or examples on how to achieve this using the curl_cffi library. My goal is to send the JSON data ({"insurance":{}}) in the field bookerChoicesJson as a part of the multipart form.

Questions: How can I send JSON data like the example above using curl_cffi in a multipart request? Is there a way to manually specify boundaries or should I rely on curl_cffi to generate boundaries automatically? Are there any best practices for handling multipart requests with JSON data in this library?

lexiforest commented 1 month ago

I think you should send them just like normal json files……

from curl_cffi import CurlMime, requests

mp = CurlMime()

mp = CurlMime.from_list(
    [
        {
            "name": "bookerChoicesJson",
            "content_type": "application/json",
            "filename": "whatever.json",
            "data": '{"insurance":{}}',
        },
    ]
)

r = requests.post("https://httpbin.org/post", multipart=mp)

Does this work for you?

el9in commented 5 days ago

Not working.