Webhook接收器响应



我有一个带有aspnet-webapi的Webhook接收器,并使用这个包

Microsoft.AspNet.WebHooks.Common
Microsoft.AspNet.WebHooks.Receivers
Microsoft.AspNet.WebHooks.Receivers.Generic

这是我的管理员

Public Class GenericJsonWebHookHandler
Inherits WebHookHandler
Public Sub New()
Me.Receiver = GenericJsonWebHookReceiver.ReceiverName
End Sub
Public Overrides Function ExecuteAsync(ByVal receiver As String, ByVal context As WebHookHandlerContext) As Task
Dim data As JObject = context.GetDataOrDefault(Of JObject)()
If data.HasValues Then
'Do something
Return Task.FromResult(True)
Else
'Here I want to return a Bad Request or a different that 200 OK
End If
End Function
End Class

我想用我收到的json进行一些验证,如果失败,我需要返回一个200 OK的不同状态,我该怎么做?

这很容易,如果有人在这里遇到同样的问题,那就是:

context.Response = context.Request.CreateResponse(HttpStatusCode.BadRequest, "Some message")
Return Task.FromResult(True)

最新更新