我想从外部 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/