0

hello guys i have swagger url http://somehost/swagger/index.html end methods there as shown on image: enter image description here

I am trying to create HTTP POST web request refer to one of the post method.

using System;
using System.Collections.Generic;
using System.Net.Http;
namespace SwaggerConsoleAPP
{
    class Program
    {  
        static  void Main(string[] args)
        {
            postRequest("http://somehost/api/Referral/GetReferralsByPersonalIdNumber");
                Console.ReadKey();
        }

        async  static void postRequest (string url){
            IEnumerable<KeyValuePair<string, string>> queries = new List<KeyValuePair<string, string>>() {
                new KeyValuePair<string, string>("1133221221","5642")

            };
            HttpContent q = new FormUrlEncodedContent(queries);
            using (HttpClient client = new HttpClient())
            {
                using (HttpResponseMessage responce = await client.PostAsync(url,q))
                 {
                    using (HttpContent content = responce.Content)
                    {
                        string mycontent = await content.ReadAsStringAsync();

                        Console.WriteLine(mycontent);
                    }
                 }
            }
        }
}
    }

this is console application but console writes error:

{"":["The input was not valid."]}

This is model of method enter image description here

Any help?

Manoj Choudhari
  • 5,277
  • 2
  • 26
  • 37
Vaso Miruashvili
  • 101
  • 1
  • 11

1 Answers1

0

In my opinion, key value pair is causing the problem.

The API is expecting personalIDNumber and pharmacyID as two separate parameters.

Simplest solution is to just create a class with these two properties:

public class InputFields
{
    public string personalIDNumber{get;set;}
    public string pharmacyId{get;set;}
}

This will work as long as your API has mode of this type as input parameter.

Please note that sending two parameters in HTTP body as post you may have to code additionally as mentioned here.

Hope this helps.

Manoj Choudhari
  • 5,277
  • 2
  • 26
  • 37