-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?

  • Could you be more specific? Perhaps show us the request/response. – puzzle Dec 9 '19 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 – NarendraC Dec 9 '19 at 8:29
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", "cja@xxx.com")
                };

            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"));

        }
  • yes tried.. But what about file and some para.? Where/How should I give? – NarendraC Dec 9 '19 at 10:52
  • new KeyValuePair<string, string>("username", "cja@xxx.com") these are the parameters, You have to give it like KeyValuePair – ChathuD Dec 9 '19 at 13:57
  • May be I understood the question in wrong way. – ChathuD Dec 9 '19 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 – NarendraC Dec 11 '19 at 4:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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