所以我目前正在使用 WCF 生成的代码“客户端对象”向服务发出 SOAP API 请求,我想知道如何为请求设置 Cookie header ?
最佳答案
一般情况下,我们使用HttpRequestMessageProperty
添加自定义HTTP header 。请引用以下代码。
ServiceReference1.ServiceClient client = new ServiceReference1.ServiceClient();
try
{
using (OperationContextScope ocs=new OperationContextScope(client.InnerChannel))
{
var requestProp = new HttpRequestMessageProperty();
requestProp.Headers["myhttpheader"] = "Boom";
OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = requestProp;
var result = client.SayHelloAsync();
Console.WriteLine(result.Result);
}
结果。
WebOperationContext 是 OperationContext 的便利包装器。目前还没有在Aspnet Core中实现。
https://github.com/dotnet/wcf/issues/2686
如果有什么我可以帮忙的,请随时告诉我。
关于api - ASP.NET Core 使用 WCF 客户端发出 SOAP API 请求如何向请求添加 Cookie header ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59257689/