I have a client who's customer uses a third party clearinghouse to receive invoices. We can do this manually by exporting our data to XML, going to a particular website, and uploading the file. The relevant HTML form looks like this:
<form border=0 method="POST" action="/server?request=send" enctype="multipart/form-data" id="uploadform" name="uploadform" onsubmit="return checkUpload()"> <H2>Upload</H2> <p>Server directory:<br> <input type="text" id="directory" name="directory" value="./" size="30"></p> <p>Local file to be uploaded:<br> <input type="file" id="file" name="file" size="40"></p> <p><input type="submit" value="Send"></p> </form>
Manual submission using their web interface works fine. I'm trying to write a quick tool that submits the form for us using
curl. I've tried many different attempts, but so far, each one, although I get a "File successfully uploaded" HTML response, the file they get is empty.
We originally started trying to use
curl because it was how the clearinghouse company suggested we do so. The example they gave was this:
curl -i -k -H "Content-Type:application/octet-stream" \ -d @test.txt -u username:password \ https://example.com/server?request=send?filename=test.txt?directory=DX001
When that didn't work, I began looking at the code in the form above, and tried the following (while in the same directory as the XML file):
curl -F "request=send" -F "directory=DX001" -F "file=33823.xml" \ -u username:password -F "enctype=\"multipart/form-data\"" \ -F "id=\"uploadform\"" https://example.com/server
When that didn't work, I thought I'd try the absolute path even though I was in the same directory:
curl -F "request=send" -F "directory=DX001" -F "file=/Users/chuck/Desktop/33823.xml" \ -u username:password -F "enctype=\"multipart/form-data\"" \ -F "id=\"uploadform\"" https://example.com/server
Every single one of these only uploads an empty file (with the given file's name).
As you can probably tell from the full path, I'm doing this from macOS, in case that's relevant.
onsubmit action within the form simply ensures that neither the
directory nor the
file inputs are empty.