I'm working with another system that expects a file as part of a POST request. When I test the system's API using the web-based test tool they provide, it works fine. This is what the request looks like in Fiddler:
You'll note that the data in the File field looks gibberish. This is because the test tool is actually sending the file as raw data (the web browser handles that part), and Fiddler attempts to encode it as ASCII. But the test itself succeeds.
OK, so here is how I try to simulate this in Workflow...
I'm first reading the edoc using a script and putting its data into a MemoryStream. Then I convert that stream into an array and concatenate the contents into one string, which I store in a token called %(Binary), which has a token tag of "File".
protected override void Execute() { DocumentInfo di = this.BoundEntryInfo as DocumentInfo; string contentType = "application/msword"; string binaryValue; using (LaserficheReadStream file = di.ReadEdoc(out contentType)) { using (MemoryStream mstream = new MemoryStream()) { file.CopyTo(mstream); concatStreamArray = string.Join("", mstream.ToArray()); SetTokenValue("binary", concatStreamArray); } } }
Then I plug that token into the HTTP Form Post activity:
When I test the workflow though, this is what Fiddler shows:
You'll note that Workflow is sending a string representation of the data, rather than the raw data like the test tool. It even automatically sets Content-Transfer-Encoding to binary, but doesn't convert the string to binary (like it should, since the token has a "File" tag and Field type is set to "File").
I tried to put the MemoryStream object directly into the %(binary) token, but the HTTP activity gets canceled with "Attempted to access an unloaded AppDomain" error when I do that.
I also tried setting the token tag of %(binary) to Byte Array and storing mstream.ToArray() inside %(binary), but when I do that, Workflow sends only the first byte in the array when it makes the POST request.
So the question is: can Workflow make an HTTP Form Post request that looks like the first Fiddler screenshot above?