How can I add an extra http header using IHTTPNegotiate?

混江龙づ霸主 提交于 2019-12-06 05:11:30

问题


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;

回答1:


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.

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.

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.



来源:https://stackoverflow.com/questions/19278466/how-can-i-add-an-extra-http-header-using-ihttpnegotiate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!