简体   繁体   中英

Can't call Asp.net Webapi custom method using Postman

I am trying to call custom name method name in webapi class. I am using Postman and able call Get method but not CusActivity method. Postman is not throwing any error either.

What is wrong here?

config.Routes.MapHttpRoute(
    name: "DefaultApi",
    routeTemplate: "api/{controller}/{id}",
    defaults: new { id = RouteParameter.Optional }
);
config.Routes.MapHttpRoute(
    name: "ApiWithAction",
    routeTemplate: "api/{controller}/{action}/{id}",
    defaults: new { id = RouteParameter.Optional }
);



public class CusActivityController : ApiController
{
    public IEnumerable<string> Get()
    {
        return new string[] { "value1", "value2" };
    }

    [HttpPost]
    public string CusActivityInsert(string userToken, string masterCustomerId, string activityText)
    {

    }

}

In POSTMAN

http://localhost:52957/api/CusActivity/CusActivityInsert

{
"userToken": "userToken1",
"masterCustomerId": "3440214",
"activityText": "ID01-Membership."
}

Your API only has one parameter in config.

You need change parameter of your action API to

public string CusActivityInsert(UserToken item)
{

}

with class

public class UserToken
{        
        public string userToken { get; set; }
        public string masterCustomerId { get; set; }
        public string activityText { get; set; }
}

If you want to keep current parameter, change PostMan API URL to

http://localhost:56433/api/CusActivity/CusActivityInsert?userToken=userToken1&masterCustomerId=3440214&activityText=ID01-Membership .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM