我有一個帶有 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 的不同狀態,我該怎么做?
uj5u.com熱心網友回復:
這很容易,如果有人在這里遇到同樣的問題,那就是:
context.Response = context.Request.CreateResponse(HttpStatusCode.BadRequest, "Some message")
Return Task.FromResult(True)
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/511610.html
標籤:VB.netasp.net-web-api网络挂钩接收者
