如何使用IHTTPNegotiate添加额外的HTTP标头? [英] How can I add an extra http header using IHTTPNegotiate?

查看:357
本文介绍了如何使用IHTTPNegotiate添加额外的HTTP标头?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用IHTTPNegotiate向请求添加额外的标题?我添加了界面,但功能 BeginningTransaction& OnResponse 永远不会被调用。

How can I add an extra header to the request using IHTTPNegotiate? I added the interface but functions BeginningTransaction & OnResponse never get called.

TNameSpaceHandler = class(TComObject, IInternetProtocol, IHttpNegotiate)  
...
    function BeginningTransaction(szURL, szHeaders: LPCWSTR; dwReserved: DWORD;
        out szAdditionalHeaders: LPWSTR): HResult; stdcall;
    function OnResponse(dwResponseCode: DWORD; szResponseHeaders, szRequestHeaders: LPCWSTR;
        out szAdditionalRequestHeaders: LPWSTR): HResult; stdcall;
...
end;


推荐答案

我默默地假设你正在拦截流量实现 IInternetProcol IInternetProtocolSink IInternetBindInfo 接口,并调用原始的 IInternetProtocol 完成工作。在这种情况下,请知道谁调用谁的方向。

I'm silently assuming you're intercepting traffic by both implementing IInternetProcol and the IInternetProtocolSink and IInternetBindInfo interfaces, and call the original IInternetProtocol to have the work done. In that case it's important to know the direction of who calls who.

如果原始处理程序需要额外的头文件,那么它将首先将您的 IInternetProtocolSink IServiceProvider 界面(带 QueryInterface ),并调用 IHttpNegotiate 实例的QueryService 。为方便起见,您可以添加当前对象实例,并在同一个对象上实现 IHttpNegotiate ,但不是必需的。

If the original handler want the additional headers, it will first cast your IInternetProtocolSink into a IServiceProvider interface (with QueryInterface), and call QueryService for an IHttpNegotiate instance. By convenience you can add the current object instance and also implement IHttpNegotiate on the same object, but this is not required.

当您的 IHttpNegotiate BeginTransaction 方法被调用时,获取一个 IHttpNegotiate ProtSink 中的c $ c>实例,调用 BeginTransaction 并在传递之前添加头文件他们到呼叫者。

When the BeginTransaction method of your IHttpNegotiate gets called, get a IHttpNegotiate instance on the ProtSink of the Start call, call BeginTransaction and add your header(s) before passing them to the caller.

这篇关于如何使用IHTTPNegotiate添加额外的HTTP标头?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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