gpt4 book ai didi

.net - 如何在 BeforeSendRequest 中取消请求

转载 作者:行者123 更新时间:2023-12-04 12:59:03 38 4
gpt4 key购买 nike

使用 IClientMessageInspector 时接口(interface),我可以取消来自BeforeSendRequest 的请求吗?方法?返回 null无论如何发送请求。

 public object BeforeSendRequest(ref Message request, IClientChannel channel)
{
if(Condition)
{
return null; //I want cancel my send
}
else
{
return request;
}
}

最佳答案

您可以使用 IClientChannel 的 Abort 方法取消请求。但是您客户的调度方法抛出 CommunicationObjectAbortedException .

public object BeforeSendRequest(ref Message request, IClientChannel channel)
{
if(Condition)
{
channel.Abort();
return null;
}
else
{
return request;
}
}

关于.net - 如何在 BeforeSendRequest 中取消请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16696750/

38 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com