I’m talking to an API, using c# RestSharp, where I need to attach files to a form request that goes to a government entity. When I use Postman and select files under the “Body” button, the files get attached correctly (apparently) and are accepted by the API. But when I use the c# RestSharp code generated by Postman and execute the exact same code, including the exact same files, from my own application, the API rejects my files as an “invalid file type”.
When I use the Postman Console to intercept each request using its rawest visual format, I see slightly different formats for the included files coming from Postman vs coming from my own application. The Postman request looks like this:
Content-Disposition: form-data; name="vehinspection"; filename="Inspect.jpg"
<Inspect.jpg>
But from my own application, using Postman as a proxy, the included file looks like this:
Content-Disposition: form-data; name="vehinspection"; filename="Inspect.jpg"
Content-Type: application/octet-stream
Encoded data .....
So the RestSharp.Request.AddFile(name, path) from my app encoded the data and attached it. But Postman has that <inspect.jpg> as the included file. How did it format the inclusion of that file in the form request?
My question is what is Postman doing differently that I need to do to make this work. The “AddFile()” function suggested by Postman formatted the file’s form data differently, apparently, than what my own application is doing (and what Postman suggested I do).
Thanks for your help!