且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

向简单 Web 服务请求添加标头

更新时间:2022-03-18 23:56:29

如果我理解正确,您想在请求的标题上设置用户名和密码.您可以通过将 WCF Extensibility – Message InspectorsIClientMessageInspector.BeforeSendRequest 结合使用来实现.

If i understand correctly, you want to set username and password on the header of the requests. You can achieve by using WCF Extensibility – Message Inspectors with IClientMessageInspector.BeforeSendRequest.

创建一个实现 IClientMessageInspector 的类.在 BeforeSendRequest 方法中,将您的自定义标头添加到传出消息中.

Create a class that implements IClientMessageInspector. In the BeforeSendRequest method, add your custom header to the outgoing message.

请参阅这个this这个