【发布时间】:2019-06-04 04:44:12
【问题描述】:
我想在本地测试 Podio webhook。我正在使用Conveyor.cloud 进行隧道传输,并使用他们的 Twilio 示例成功对其进行了测试。我在将代码转换为使用 Podio 时遇到的问题是 Twilio 示例使用了控制器,而 http://podio.github.io/podio-dotnet/webhooks/ 的 Podio webhook 示例使用了 IHttpHandler。
我尝试在下面的代码中将 IHttpHandler 实现到控制器,但它不起作用。
using System;
using System.Web;
using System.Web.Mvc;
using PodioAPI;
namespace WebhooksProject.Controllers
{
public class WebController : IHttpHandler
{
public static string clientId = "abcd";
public static string clientSecret = "abcd";
public static string username = "a@b.com";
public static string password = "abcd";
public static Podio podio = new Podio(clientId, clientSecret);
public void ProcessRequest(HttpContext context)
{
podio.AuthenticateWithPassword(username, password);
var request = context.Request;
switch (request["type"])
{
case "hook.verify":
podio.HookService.ValidateHookVerification(int.Parse(request["hook_id"]), request["code"]);
break;
// An item was created
case "item.create":
// For item events you will get "item_id", "item_revision_id" and "external_id". in post params
int itemIdOfCreatedItem = int.Parse(request["item_id"]);
// Fetch the item and do what ever you want
break;
// An item was updated
case "item.update":
// For item events you will get "item_id", "item_revision_id" and "external_id". in post params
int itemIdOfUpdatedItem = int.Parse(request["item_id"]);
// Fetch the item and do what ever you want
break;
// An item was deleted
case "item.delete":
// For item events you will get "item_id", "item_revision_id" and "external_id". in post params
int deletedItemId = int.Parse(request["item_id"]);
break;
}
}
public bool IsReusable
{
get{return false;}
}
}
}
我错过了什么?
【问题讨论】:
-
为什么要实现HttpHandler?您可以使用普通的控制器操作来完成
-
@AkbarBadhusha 我尝试只使用正常的控制器操作,但我不知道如何访问
context。在带有 Twilio 示例的原始控制器中,我有一个 Index 方法:public TwiMLResult Index(SmsRequest request) { var response = new MessagingResponse(); response.Message("Hello World"); return TwiML(response); }This 提供了一个 SmsRequest 对象。如何获取 Podio 对象?我的方向正确吗? -
为什么需要上下文?