-2

Team, I am trying to provide File and some para. as a input for API. Expecting output based on validation.

Even after providing both inputs correctly, I am getting File as null with length 0. Below are the details of my env:

  • Windows 11
  • API Automation
  • POST method

How to provide File and some para. to POST API?

2
  • Could you be more specific? Perhaps show us the request/response.
    – pavelsaman
    Dec 9, 2019 at 8:23
  • Actually found many solutions for sending file to POST but with file I want to send some para. too. I have created File obj and I am able to see file fetch successfully as length is > 0 but its become null when it calls server functions Dec 9, 2019 at 8:29

1 Answer 1

0

Some thing like this

   public void POST_GetClientList()
        {
            string url = "https://XXXXX.XXX.XXX/GetClientList";
            string OutPutdata = null;
            byte status = 0;
            string ResponsCode = null;


            var client = new HttpClient();
            var pairs = new List<KeyValuePair<string, string>>
                {
                    new KeyValuePair<string, string>("username", "[email protected]")
                };

            try
            {
                var content = new FormUrlEncodedContent(pairs);
                var response = client.PostAsync(url, content).Result;
                ResponsCode = response.ToString().Substring(12, 3);

            }
            catch (Exception)
            {

            }


            Assert.IsTrue(ResponsCode.Contains("200"));

        }
4
  • yes tried.. But what about file and some para.? Where/How should I give? Dec 9, 2019 at 10:52
  • new KeyValuePair<string, string>("username", "[email protected]") these are the parameters, You have to give it like KeyValuePair
    – ChathuD
    Dec 9, 2019 at 13:57
  • May be I understood the question in wrong way.
    – ChathuD
    Dec 9, 2019 at 13:58
  • No - What you are saying is correct I have implemented in somewhat same way but just can't proceed as I have to send File and two more parameter simultaneously. If I did so - File obj is getting null :( Finding the solutions. Hope if you have solution for this Dec 11, 2019 at 4:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.