0

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
Dijkgraaf
  • 11,049
  • 17
  • 42
  • 54
NealWalters
  • 17,197
  • 42
  • 141
  • 251

1 Answers1

0

I finally installed WireShark, and fortunately my URL was http and not https. This is how my message needed to be formatted. However, even with this matching (except for the few hex characters at the beginning), I still couldn't get the same result from BizTalk as I was getting from C# call (using RestSharp), so that part is still a mystery.

The boundary can be any string, but should start with --. I just made it the same as the random number/GUID assigned by RestSharp so I could do a side-by-side compare and eliminate the number of differences.

¬PVbLE_Ë@
 ñ
 hîÄPßbò½¹JP >-----------E4CF74B8-81A2-4B7F-8459-54218CF53B4B
Content-Disposition: form-data; name="to"

073123123
-----------E4CF74B8-81A2-4B7F-8459-54218CF53B4B
Content-Disposition: form-data; name="from"

006123123
-----------E4CF74B8-81A2-4B7F-8459-54218CF53B4B
Content-Disposition: form-data; name="name"

input-data
-----------E4CF74B8-81A2-4B7F-8459-54218CF53B4B
Content-Disposition: form-data; name="input-format"

X12
-----------E4CF74B8-81A2-4B7F-8459-54218CF53B4B
Content-Disposition: form-data; name="input-data"; filename="006943500-073123123-2021021054572-G873RRFC.edm"
Content-Type: text/plain

ISA*00*          *00*          *01*006123123      *01*073123123      etc~IEA*1*000002744~~IEA*1*000002744~
NealWalters
  • 17,197
  • 42
  • 141
  • 251