【问题标题】:Calling Web API method in postman在 postman 中调用 Web API 方法
【发布时间】:2019-03-31 19:55:23
【问题描述】:

我正在尝试在 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;
        }

任何建议表示赞赏。

【问题讨论】:

  • 到目前为止你尝试过什么?而且您可能希望格式化您的代码,使其可读...
  • 格式化代码。
  • 这里详细说明如何认证用户,然后通过post mastackoverflow.com/questions/42976982/…与api通信
  • 如何在 Postman GET 和 POST 请求中调用用户控制器中的 GetAllNotifications 方法

标签: asp.net-web-api


【解决方案1】:

只需在 localhost 中运行您的项目并从浏览器中复制 URL 并添加 您的 Api 名称,例如,如果项目使用以下 url 运行:https://localhost:3000/api/values

只需使用您的 api 名称更改 url 来代替“values” https://localhost:3000/api/GetAllNotifications 现在将此 url 粘贴到邮递员中并设置 get 方法并单击发送确保您的项目在相同的 localhost 端口号中运行。

【讨论】:

    猜你喜欢
    • 2019-04-27
    • 1970-01-01
    • 2021-08-25
    • 2014-12-11
    • 2020-04-06
    • 1970-01-01
    • 2021-09-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多