It's about multipart requests.

Asked 2 years ago, Updated 2 years ago, 27 views

POST/v2/users/create HTTP/1.1
Host: mixch.tv
Connection:keep-alive
X-Mixch-Country:jp
X-Mixch-Attribution:Organic
Accept: */*
X-Mixch-AdvertisingId: A29428C7-8C02-419F-A071-E47E3DA184A9
User-Agent: mixch/5.2.1 (iPhone; iOS 10.2; Scale/2.00)
Accept-Language: ja-JP;q=1
Accept-Encoding: gzip, deflate
Content-Length—262033
Content-Type: multipart/form-data; boundary=Boundary+EF9D031E6AE26D0E

-- Boundary + EF9D031E6AE26D0E
Content-Disposition: form-data; name="birth_year"

-1
-- Boundary + EF9D031E6AE26D0E
Content-Disposition: form-data; name="nickname"

hi
-- Boundary + EF9D031E6AE26D0E
Content-Disposition: form-data; name="prefecture"

-1
-- Boundary + EF9D031E6AE26D0E
Content-Disposition: form-data; name="file"; filename="file.png"
Content-Type: image/jpeg

����

Please tell me how to send this multipart request...
Python 2, please.

python

2022-09-30 20:19

1 Answers

There is an example of a proper multipart in the documentation.
http://requests.readthedocs.io/en/latest/user/quickstart/ #post-a-multipart-encoded-file

import requests


data=dict(
    birth_year=-1,
    nickname = "Hi",
    perfect=-1,
)

files=dict(
    file=open('xxx.png','rb')
)

r=requests.post('http://localhost:8888', files=files, data=data)
print(r.text)

Running as nc-l8888 on a different terminal indicates that the following is being POSTed:The Boundary ID is a random string that is determined at runtime, so you don't have to worry about the value.

$nc-l8888
POST/HTTP/1.1
Host:localhost:8888
User-Agent: python-requests/2.18.1
Accept-Encoding: gzip, deflate
Accept: */*
Connection:keep-alive
Content-Length:420
Content-Type: multipart/form-data; boundary=177b060d764643c398b667b5841c06df

-- 177b060d764643c398b667b5841c06df
Content-Disposition: form-data; name="birth_year"

-1
-- 177b060d764643c398b667b5841c06df
Content-Disposition: form-data; name="nickname"

hi
-- 177b060d764643c398b667b5841c06df
Content-Disposition: form-data; name="prefecture"

-1
-- 177b060d764643c398b667b5841c06df
Content-Disposition: form-data; name="file"; filename="xxx.png"


-- 177b060d764643c398b667b5841c06df --


2022-09-30 20:19

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.