1

またはを使用してすべてのリクエストヘッダーを取得するにはどうすればよいですOIBindInfoIWinInetHttpInfo? 私はこれを使用しStartますが、変数HeadersまたはRequestHeaders常に空ですか?

を使用したアプローチOIBindInfo:

function THandler.Start(szUrl: PWideChar; OIProtSink:
IInternetProtocolSink; OIBindInfo: IInternetBindInfo; grfPI, dwReserved:
DWORD): HResult; stdcall;
var
    dwSize: ULONG;
    pszHeaders: POleStr;
    Headers: String;
begin
    OIBindInfo.GetBindString(BINDSTRING_HEADERS, @pszHeaders, 1, dwsize)
    Headers := PWideChar(pszHeaders); // weird result of Headers = ჸ
    CoTaskMemFree(pszHeaders);
    pszHeaders := nil;
    Result := INET_E_USE_DEFAULT_PROTOCOLHANDLER;
end;

を使用したアプローチIWinInetHttpInfo:

type
  THandler = class(TComObject, IInternetProtocol, IWinInetHttpInfo)
    private
      ServiceProvider: IServiceProvider;
      WinInetHttpInfo: IWinInetHttpInfo;
      URL: String;
      RequestHeaders: String;
      function QueryInfoEx(dwOption: DWORD; var Info: string): Boolean;
    protected
      function Start(szUrl: PWideChar; OIProtSink: IInternetProtocolSink;
        OIBindInfo: IInternetBindInfo; grfPI, dwReserved: DWORD): HResult; stdcall;
      function Continue(const ProtocolData: TProtocolData): HResult; stdcall;
      function Abort(hrReason: HResult; dwOptions: DWORD): HResult; stdcall;
      function Terminate(dwOptions: DWORD): HResult; stdcall;
      function Suspend: HResult; stdcall;
      function Resume: HResult; stdcall;
      function Read(pv: Pointer; cb: ULONG; out cbRead: ULONG): HResult; stdcall;
      function Seek(dlibMove: LARGE_INTEGER; dwOrigin: DWORD;
        out libNewPosition: ULARGE_INTEGER): HResult; stdcall;
      function LockRequest(dwOptions: DWORD): HResult; stdcall;
      function UnlockRequest: HResult; stdcall;
      function QueryInfo(dwOption: DWORD; Buffer: Pointer; var cbBuf, dwFlags, dwReserved: DWORD): HResult; stdcall;
      function QueryOption(dwOption: DWORD; Buffer: Pointer; var cbBuf: DWORD): HResult; stdcall;
  end;

function THandler.QueryInfoEx(dwOption: DWORD; var Info: string): Boolean;
var
  Buf: array[0..INTERNET_MAX_PATH_LENGTH] of AnsiChar;
  BufLength, dwReserved, dwFlags: Cardinal;
begin
    dwReserved := 0;
    dwFlags := 0;
    BufLength := INTERNET_MAX_PATH_LENGTH + 1;
    Result := not Boolean(WinInetHttpInfo.QueryInfo(dwOption, @Buf, BufLength, dwFlags, dwReserved));
    if Result then 
    Info := string(Buf);
end;

function THandler.Start(szUrl: PWideChar; OIProtSink:
IInternetProtocolSink; OIBindInfo: IInternetBindInfo; grfPI, dwReserved:
DWORD): HResult; stdcall;
begin
  OIProtSink.QueryInterface(IServiceProvider, ServiceProvider);
  OIProtSink.QueryInterface(IWinInetHttpInfo, WinInetHttpInfo);
  QueryInfoEx(HTTP_QUERY_RAW_HEADERS, RequestHeaders); // empty RequestHeaders
  Result := INET_E_USE_DEFAULT_PROTOCOLHANDLER;
end;

どちらも機能していません!

4

1 に答える 1