使用wiremock.net的SDK,我试图在响应上链接一个webhook。
.RespondWith(Response.Create()
.WithStatusCode(200)
.WithHeader("Content-Type", "application/json")
.WithBodyAsJson(newOrder)
);
您需要使用WithWebhook(...)
方法,这在Wiki上有描述。
查看这个示例代码,它将发送一个post-request到webhook。
var server = WireMockServer.Start();
server.Given(Request.Create().UsingPost())
.WithWebhook(new Webhook
{
Request = new WebhookRequest
{
Url = "https://any-endpoint.com",
Method = "post",
BodyData = new BodyData
{
BodyAsString = "OK !",
DetectedBodyType = BodyType.String
}
}
})
.RespondWith(Response.Create().WithBody("a-response"));