将自定义 Http 标头添加到 Web 服务代理 [英] Adding Custom Http Headers to Web Service Proxy

查看:41
本文介绍了将自定义 Http 标头添加到 Web 服务代理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个旧的应用程序,它使用经典的 Web 服务代理与 Java Web 服务交互.不久前,Web 服务托管商决定要求每个请求都发送一个自定义 HTTP 标头,以便访问服务 - 否则请求将被彻底抛出(看起来这是某种路由器要求).无论我需要将自定义 HTTP 标头注入请求的原因是什么.

I have an old application that uses the classic Web Service Proxy to interact with a Java Web Service. A while back the Web Service hoster decided to require a custom HTTP header to be sent with each request in order to access the service - otherwise the requests are thrown out outright (looks like this is some sort of router requirement). Regardless of what the reason I need to inject a custom HTTP header into the request.

有什么方法可以与实际的 Http 客户端交互以执行添加自定义标头之类的操作吗?

Is there any way to interact with the actual Http client to do things like add custom headers?

推荐答案

您应该能够通过在单独文件中的分部类中重写代理类的 GetWebRequest 方法来实现此目的.调用基类方法后,你应该可以随意修改返回的HttpWebRequest,然后从方法中返回:

You should be able to do this by overriding the GetWebRequest method of the proxy class in a partial class in a separate file. After calling the base class method, you should be able to modify the returned HttpWebRequest however you like, then return it from the method:

public partial class MyServiceProxy {
    protected override WebRequest GetWebRequest(Uri uri) {
        HttpWebRequest request = (HttpWebRequest) base.GetWebRequest(uri);
        // do what you will with request.
        return request;
    }
}

这篇关于将自定义 Http 标头添加到 Web 服务代理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆