Skip to content
This repository has been archived by the owner on Dec 25, 2020. It is now read-only.

file上传缺少form相应设置 #8

Closed
gyje opened this issue Dec 6, 2019 · 1 comment
Closed

file上传缺少form相应设置 #8

gyje opened this issue Dec 6, 2019 · 1 comment

Comments

@gyje
Copy link

gyje commented Dec 6, 2019

fiddler 抓包信息:

------WebKitFormBoundaryBUZFWBgRBSOaC51N
Content-Disposition: form-data; name="entrustNos"

20190038713
------WebKitFormBoundaryBUZFWBgRBSOaC51N
Content-Disposition: form-data; name="fileList[0].fileName"

request paper
------WebKitFormBoundaryBUZFWBgRBSOaC51N
Content-Disposition: form-data; name="fileList[0].fileRemark"


------WebKitFormBoundaryBUZFWBgRBSOaC51N
Content-Disposition: form-data; name="uploadArr"; filename="38713.pdf"
Content-Type: application/pdf

%PDF-1.3
%    
1 0 obj
<< 
/Creator (Canon SC1011)
......

用python requests可以这样写:

......
files = {
	'entrustNos': [None, '20190038713'],
	'fileList[0].fileName': [None, 'request paper'],
	'fileList[0].fileRemark': [None, None],
	'uploadArr': ['38713.pdf', open('38713.pdf', 'rb'), 'application/pdf']
}

response = rq.post('http://xxx.com', headers=headers, cookies=cookies, files = files)

翻看nic的源码没发现相应的处理方式。

@EddieIvan01
Copy link
Owner

修改MIME Form的功能在v0.2.1版本已经加入了,您是不是没有下载最新版

https://github.com/EddieIvan01/nic/blob/master/options.go#L44-L83

r, _ := nic.Post("http://127.0.0.1", nic.H{
    Files: nic.KV {
        "entrustNos": "20190038713",
        "fileList[0].fileName": "request paper",
        "fileList[0].fileRemark": "",
        "uploadArr": nic.FileFromPath("./38713.pdf").MIME("application/pdf"),
    },
})
--e917a640b5bac1addff4a7d483b39d72416ddd74adcb4d360ef33b37284d
Content-Disposition: form-data; name="entrustNos"

20190038713
--e917a640b5bac1addff4a7d483b39d72416ddd74adcb4d360ef33b37284d
Content-Disposition: form-data; name="fileList[0].fileName"

request paper
--e917a640b5bac1addff4a7d483b39d72416ddd74adcb4d360ef33b37284d
Content-Disposition: form-data; name="fileList[0].fileRemark"


--e917a640b5bac1addff4a7d483b39d72416ddd74adcb4d360ef33b37284d
Content-Disposition: form-data; name="uploadArr"; filename="38713.pdf"
Content-Type: application/pdf

%PDF-1.3

--e917a640b5bac1addff4a7d483b39d72416ddd74adcb4d360ef33b37284d--

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants