在postman中调用Web API方法

时间:2017-09-07 05:37:41

标签: asp.net-web-api

我试图在Postman中调用以下Web API方法:

public HttpResponseMessage GetAllNotifications(HttpRequestMessage request, String Name)
        {
            HttpResponseMessage response = null;
            try
            {
                List<ExpandoObject> res = _userProcess.GetAllNotifications(Name);
                response = request.CreateResponse<List<ExpandoObject>>(HttpStatusCode.OK, res);
            }
            catch (Exception ex)
            {
                response = request.CreateResponse<string>(HttpStatusCode.BadRequest, "Unable to process your request Please contact administration");
                throw new DataException(ex.Message.ToString());
            }
            return response;
        }

任何建议表示赞赏。

1 个答案:

答案 0 :(得分:0)

只需在localhost中运行您的项目,然后从浏览器复制Url并添加 您的Api名称,如果项目以类似https://localhost:3000/api/values

的网址运行,则为示例

只需用您的api名称代替“ values”更改网址 https://localhost:3000/api/GetAllNotifications,然后将此URL粘贴到postman中并设置get方法,然后单击send以确保您的项目在相同的本地主机端口号上运行。