0 votes
by (130 points)

I need to send an HTTP post that has data and the contents of a file in the body of the post message. Is there any method similar to UploadData/UploadFile in which I can send the URI, the JSON data, and the File needed for the form-data?

1 Answer

+1 vote
by (145k points)

You can use Rebex HttpRequest class to send "multipart/form-data" requests, which can contain multiple parts using the approach described in answers to this StackOverflow question: https://stackoverflow.com/questions/566462/upload-files-with-httpwebrequest-multipart-form-data

To adapt the code to use Rebex API, replace this line:

HttpWebRequest wr = (HttpWebRequest)WebRequest.Create(url);

With this:

var creator = new HttpRequestCreator();
HttpRequest request = creator.Create(url);

However, make sure this is actually the request form expected by the web service you are calling. The web services' documentation should make it clear what kind of requests the HTTP client is supposed to use.