I m calling a WebApi method and passing data to it. While debugging I can see my control go to WebAPI method but it is not receiving correct parameter data which I m passing to it. While debugging I can see data (a string) is being passed to WebApi but on next step WebApi receives null. Is some configuration required to received parameter ? Please help me below is my code:
public static string PostData(Uri url,string obj)
{
string data = null;
try
{
using (WebClient proxy = new WebClient())
{
proxy.Headers.Add(HttpRequestHeader.ContentType, "application/json");
data = proxy.UploadString(url,"Post",obj);
}
}
catch (Exception ex)
{
throw ex;
}
return data;
}
WebAPI
[HttpPost]
public void Post([FromBody]string data)
{
leadOptService.AddListOptions(data);
}
WebApi Conifg:
public static void Register(HttpConfiguration config)
{
// Web API configuration and services
// Web API routes
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
}