I'm trying to send data using a multi-part form in BizTalk. BizTalk is great for calling APIs but not so great for posting to a web/page form, so I'm doing it a crude raw text format. So this question is not so specific to BizTalk, but how to properly format the data to be posted.
Part of what I'm doing is based on this StackOverflow Question.
This is currently my best understanding of what I should be sending in raw format. If I'm correct, I need to repeat the boundary between each form field (there are three: input-format=X12, to=Some number, from=Some number, and then a file is uploaded as well):
--_BiztalkUploadEDIMultipartBoundary_
Content-Disposition: form-data; name="input-format"
X12
--_BiztalkUploadEDIMultipartBoundary_
Content-Disposition: form-data; name="to"
073123123
--_BiztalkUploadEDIMultipartBoundary_
Content-Disposition: form-data; name="from"
006123123
--_BiztalkUploadEDIMultipartBoundary_
Content-Type: application/binary; name=filename-2021021054572-G873RRFC.edm
Content-Transfer-Encoding: binary
Content-Disposition: form-data; name=file; filename=filename-2021021054572-G873RRFC.edm
ISA*00* *00* *01*006123123 *01*073123123 *210210*2122*+*00502*000002744*1*P*^~GS*CU*
etc
~IEA*1*000002744~
--_BiztalkUploadEDIMultipartBoundary_--
I'm wondering if I need Content-Type on the data fields?
A coworker was able to submit data with this sample Python program:
import requests
url = "http://x.x.x.x:5712/UPLOAD"
payload = {'input-format': 'X12', 'to': '073123123', 'from': '808123123', 'name': 'input-data'}
files = [
('input-data', ('808150895_073394164.63490032', open(r'\\vhdc-wwqrm21m\EDI\MO\808150895_073394164.33490128', 'rb'),
'application/octet-stream'))
]
headers = {}
response = requests.request("POST", url, headers=headers, data=payload, files=files)
print(response.text)
I'm currently getting an error back that my co-worker said means we didn't pass the "to" and "from" correctly.
Also is a space (new/line) required between a form fieldname and the form value? Is Sample 1 or Sample 2 correct?
Sample 1
Content-Disposition: form-data; name="input-format"
X12
Sample 2
Content-Disposition: form-data; name="input-format"
X12