web stats
multipart POST with HTTP Sender - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 01-31-2017, 01:46 PM
jnankin jnankin is offline
Mirth Newb
 
Join Date: Jan 2017
Posts: 6
jnankin is on a distinguished road
Default multipart POST with HTTP Sender

I see the "multipart" radio button in HTTP Sender, but I don't see any place to add a multipart form parameter or part.

I'd simply like to add a part with a filename and content type and then add some binary or base64 encoded data. I don't see anything in the documentation that would describe how I do this.

Has anyone used the "Multipart" option before?
Reply With Quote
  #2  
Old 01-31-2017, 02:04 PM
narupley's Avatar
narupley narupley is online now
Mirth Employee
 
Join Date: Oct 2010
Posts: 7,119
narupley is on a distinguished road
Default

The current multipart option is very "simple". When used, the HTTP Sender will dispatch a multipart/form-data request with a single part.

We have an open issue to improve the options and allow easily adding multiple parts, so please comment on it if you'd like to see it in a future version: MIRTH-1940

In the meantime it's still possible, but you'll just have to build up the multipart payload yourself (with boundaries) and use that in the Content field.
__________________
Step 1: JAVA CACHE...DID YOU CLEAR ...wait, ding dong the witch is dead?

Nicholas Rupley
Work: 949-237-6069
Always include what Mirth Connect version you're working with. Also include (if applicable) the code you're using and full stacktraces for errors (use CODE tags). Posting your entire channel is helpful as well; make sure to scrub any PHI/passwords first.


- How do I foo?
- You just bar.
Reply With Quote
  #3  
Old 02-01-2017, 12:40 AM
siddharth siddharth is offline
Mirth Guru
 
Join Date: Feb 2013
Posts: 832
siddharth is on a distinguished road
Default

I think this would help you

http://www.mirthproject.org/communit...2&postcount=43
Reply With Quote
  #4  
Old 02-01-2017, 07:51 AM
narupley's Avatar
narupley narupley is online now
Mirth Employee
 
Join Date: Oct 2010
Posts: 7,119
narupley is on a distinguished road
Default

FYI you don't have to go full JavaScript for the actual HTTP dispatching. You can still use the HTTP Sender and just build up the multipart payload.

I've attached a sample group (for version 3.4.2) and a sample inbound message. It's an HL7 message with an embedded PDF. The upstream channel takes the HL7 message, extracts the PDF as an attachment, builds up a multipart payload, and dispatches two parts (one for the HL7, one for the PDF) via a multipart/form-data HTTP request. The downstream channel parses the multipart request and extracts the PDF into an attachment.
Attached Files
File Type: xml Example - Build Multipart Payload.xml (47.1 KB, 189 views)
File Type: txt test.hl7.txt (27.8 KB, 93 views)
__________________
Step 1: JAVA CACHE...DID YOU CLEAR ...wait, ding dong the witch is dead?

Nicholas Rupley
Work: 949-237-6069
Always include what Mirth Connect version you're working with. Also include (if applicable) the code you're using and full stacktraces for errors (use CODE tags). Posting your entire channel is helpful as well; make sure to scrub any PHI/passwords first.


- How do I foo?
- You just bar.
Reply With Quote
  #5  
Old 02-02-2017, 01:25 PM
jnankin jnankin is offline
Mirth Newb
 
Join Date: Jan 2017
Posts: 6
jnankin is on a distinguished road
Default

I must be doing something wrong, but I can't get \r\n line endings using the Content text area. Also, Mirth injectes the Charset encoding into my Content-Type header, but I don't think its supposed to be there.

Here's what I have set up:

------WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="file"; filename="inflation.txt"
Content-Type: text/plain

hi
------WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="to"

+18662495773
------WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="api_key"

REDACTED
------WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="api_secret"

REDACTED
------WebKitFormBoundary7MA4YWxkTrZu0gW--



Here is what it's sending:

HTTPServerRequest(protocol='http', host='61539689.ngrok.io', method='POST', uri='/', version='HTTP/1.1', remote_ip='::1', headers={'Content-Length': '537', 'Accept-Encoding': 'gzip,deflate', 'X-Forwarded-For': '54.203.145.63', 'Content-Type': 'multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW; charset=UTF-8', 'Host': '61539689.ngrok.io', 'User-Agent': 'Apache-HttpClient/4.5.1 (Java/1.7.0_121)'})
'------WebKitFormBoundary7MA4YWxkTrZu0gW\nContent-Disposition: form-data; name="file"; filename="inflation.txt"\nContent-Type: text/plain\n\nhi\n------WebKitFormBoundary7MA4YWxkTrZu0gW\nContent-Disposition: form-data; name="to"\n\n+18662495773\n------WebKitFormBoundary7MA4YWxkTrZu0gW\nContent-Disposition: form-data; name="api_key"\n\nREDACTED\n------WebKitFormBoundary7MA4YWxkTrZu0gW\nContent-Disposition: form-data; name="api_secret"\n\ndREDACTED\n------WebKitFormBoundary7MA4YWxkTrZu0gW--'
Reply With Quote
  #6  
Old 02-02-2017, 02:49 PM
jnankin jnankin is offline
Mirth Newb
 
Join Date: Jan 2017
Posts: 6
jnankin is on a distinguished road
Default

Ok, I've been able to add crlf line ending by building up the content in javascript, but I still cannot remove the charset from the content type of the request.

How can I drop the charset in this header:

Content-Type: multipart/form-data; boundary=------WebKitFormBoundary7MA4YWxkTrZu0gW; charset=UTF-8
Reply With Quote
  #7  
Old 02-07-2017, 12:19 PM
jnankin jnankin is offline
Mirth Newb
 
Join Date: Jan 2017
Posts: 6
jnankin is on a distinguished road
Default

Anyone? Thoughts?
Reply With Quote
  #8  
Old 02-08-2017, 04:04 AM
siddharth siddharth is offline
Mirth Guru
 
Join Date: Feb 2013
Posts: 832
siddharth is on a distinguished road
Default

I think you are adding that string charset=UTF-8, some where while declaring WebKitFormBoundary. If you can find it and remove, it would work.
Reply With Quote
  #9  
Old 02-08-2017, 06:15 AM
narupley's Avatar
narupley narupley is online now
Mirth Employee
 
Join Date: Oct 2010
Posts: 7,119
narupley is on a distinguished road
Default

As you can see from the example channel group I posted, if you use Binary mode then the charset is not automatically added to the content type header.
__________________
Step 1: JAVA CACHE...DID YOU CLEAR ...wait, ding dong the witch is dead?

Nicholas Rupley
Work: 949-237-6069
Always include what Mirth Connect version you're working with. Also include (if applicable) the code you're using and full stacktraces for errors (use CODE tags). Posting your entire channel is helpful as well; make sure to scrub any PHI/passwords first.


- How do I foo?
- You just bar.
Reply With Quote
  #10  
Old 02-13-2017, 09:58 AM
jnankin jnankin is offline
Mirth Newb
 
Join Date: Jan 2017
Posts: 6
jnankin is on a distinguished road
Default

Hi narupley.

I'm new to Mirth, so I'm not really sure how to use what you posted in XML and see what that looks like in Mirth Administrator.

Furthermore, if I convert the content to binary, I am not able to see the payload in clear text. I need to post multiple parts in the body of the request. Are you able to show me an example where I can send multiple parts in the multipart POST, where some parts are simply form parameters and another one is a file?

Thanks,
Josh
Reply With Quote
Reply

Tags
http, httpsender, multipart, post

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -8. The time now is 03:59 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2019, vBulletin Solutions, Inc.
Mirth Corporation