
Multipart/Form Data
A HTTP multipart request is a HTTP request that HTTP clients construct to send files and data over to a HTTP Server. It is commonly used by browsers and HTTP clients to upload files to the server.
Swagger Link : https://petstore.swagger.io/#/
Code :
[TestClass] public class DemoPostOperations { [Test] public void MultipartFormData() { var client = new RestClient("https://petstore.swagger.io/v2/"); client.Authenticator = new HttpBasicAuthenticator("api_key", "****"); var request = new RestRequest("pet/10/uploadImage", Method.POST); request.AddHeader("Content-Type", "multipart/form-data"); request.AddHeader("Accept", "application/json"); request.AddParameter("additionalMetadata", "abc123"); request.AddFile("file", @"C:\Users\Admin\source\repos\WebserviceAutomation\WebserviceAutomation\Post Operations\Screenshot_1.jpg"); IRestResponse response = client.Execute(request); var resonseContent = response.Content; } }
Response Body :
{"code":200,"type":"unknown","message":"additionalMetadata: abc123\nFile uploaded to ./Screenshot_1.jpg, 18091 bytes"}
