c# - Asp.net MVC 中的 Webhook

标签 c# asp.net-mvc asp.net-web-api

我想从外部 api 接收数据到我的 asp.net mvc 项目,并且我想知道如何编写代码以从外部 api 接收 json 数据到我的 Controller (webhook):

这是数据:

{

    "event": "tracking_update",
    "msg": {
        "id": "53aa94fc55ece21582000004",
        "tracking_number": "906587618687",
        "title": "906587618687",
        "origin_country_iso3": null,
        "destination_country_iso3": null,
        "shipment_package_count": 0,
        "active": false,
        "order_id": null,
        "order_id_path": null,
        "customer_name": null,
        "source": "web",
        "emails": [],
        "custom_fields": {},
        "tag": "Delivered",
        "tracked_count": 1,
        "expected_delivery": null,
        "signed_by": "D Johnson",
        "shipment_type": null,
        "tracking_account_number": null,
        "tracking_postal_code": "DA15BU",
        "tracking_ship_date": null,
        "created_at": "2014-06-25T09:23:08+00:00",
        "updated_at": "2014-06-25T09:23:08+00:00",
        "slug": "dx",
        "unique_token": "xk7LesjIgg",
        "checkpoints": [{
            "country_name": null,
            "country_iso3": null,
            "state": null,
            "city": null,
            "zip": null,
            "message": "Signed For by: D Johnson",
            "coordinates": [],
            "tag": "Delivered",
            "created_at": "2014-06-25T09:23:11+00:00",
            "checkpoint_time": "2014-05-02T16:24:38",
            "slug": "dx"
        }]
    },
    "ts": 1403688191
}
  • 如何在 asp.net 项目中作为 webhook 从另一个 Web api 接收 json 数据

最佳答案

这是总代码:

[HttpPost]
    public ActionResult Index()
    {
        string FileContent = "";
        using (StreamReader sr = new StreamReader(Request.InputStream))
        {
            FileContent = sr.ReadToEnd();
        }
         AfterShip model = JsonConvert.DeserializeObject<AfterShip>(FileContent);

     }

关于c# - Asp.net MVC 中的 Webhook,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38565514/

相关文章:

c# - 与泛型建立关系

c# - WinForms 按钮 : Autosize Maximumsize

c# - Telerik MVC Ajax 网格不会在保存时扩展

javascript - 如何将数据从表单传递到我的 Controller ,然后返回到我的客户端 javascript?

asp.net-web-api - Xamarin.iOS - WebApi 连接被拒绝

c# - Web API : A potentially dangerous Request. 从客户端检测到路径值

javascript - 我们能确定MVC EnableCors的由来吗?

c# - 从位串转换为整数

c# - 奇怪的 C# 编译器错误

asp.net-mvc - ASP.Net MVC : Render Html. ValidationSummary仅在出现错误时