How to provide File and some para. to POST API using Python/ C#?



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



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


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2