【问题标题】:Sending POST request with WebView/EdgeHTML使用 WebView/EdgeHTML 发送 POST 请求
【发布时间】:2020-03-10 14:36:29
【问题描述】:

我目前正在尝试根据以下答案让 EdgeHTML/WebView 工作:Using WebView (EdgeHTML) in Delphi / C++ Builder

复制代码并运行它就可以了。

但现在我正在尝试添加“NavigateWithHttpRequestMessage”过程,以便我可以发送 POST 请求并且必须意识到我不知道我应该如何为其参数创建对象。

这是程序的描述: https://docs.microsoft.com/en-us/uwp/api/windows.web.ui.iwebviewcontrol.navigatewithhttprequestmessage

它告诉我参数的类型是“HttpRequestMessage”。

我已经下载了 Windows 10 工具包,并在里面找到了 Windows.Web.Http.idl 和“HttpRequestMessage”的这个接口:

[exclusiveto(Windows.Web.Http.HttpRequestMessage)]
[uuid(F5762B3C-74D4-4811-B5DC-9F8B4E2F9ABF)]
interface IHttpRequestMessage : IInspectable
{
[propget] HRESULT Content([out] [retval] Windows.Web.Http.IHttpContent** value);
[propput] HRESULT Content([in] Windows.Web.Http.IHttpContent* value);
[propget] HRESULT Headers([out] [retval] Windows.Web.Http.Headers.HttpRequestHeaderCollection** value);
[propget] HRESULT Method([out] [retval] Windows.Web.Http.HttpMethod** value);
[propput] HRESULT Method([in] Windows.Web.Http.HttpMethod* value);
[propget] HRESULT Properties([out] [retval] Windows.Foundation.Collections.IMap<HSTRING, IInspectable*>** value);
[propget] HRESULT RequestUri([out] [retval] Windows.Foundation.Uri** value);
[propput] HRESULT RequestUri([in] Windows.Foundation.Uri* value);
[propget] HRESULT TransportInformation([out] [retval] Windows.Web.Http.HttpTransportInformation** value);
}

我可以将它转换为 Delphi 中的接口,就像 NineBerry 对上面链接中的其他接口所做的那样。 (或者至少使用虚拟程序。还不确定参数的类型。)

但是如何从中创建一个对象,以便我可以将它与“NavigateWithHttpRequestMessage”过程一起使用?

任何帮助甚至指向正确方向的指示都将不胜感激。

【问题讨论】:

    标签: delphi webview microsoft-edge


    【解决方案1】:

    根据official docs,我们可以在C#中使用这样的方法:

    var httprequest = new HttpRequestMessage(HttpMethod.Post, new Uri(url))   
    webView.NavigateWithHttpRequestMessage(httprequest);
    

    我找不到 Delphi 示例。您可以参考C# examples 并尝试将其转换为Delphi。

    【讨论】:

    • 是的,这就是目标。但是那个 HttpRequestMessage 类是从哪里来的呢?我拥有的最多的是那个接口,我不能从中创建一个对象。在 c# 中,该类位于“使用 Windows.Web.Http;”中,但它在 Delphi 中来自哪里?
    【解决方案2】:

    如果您已经对接口有所了解,答案就相当简单。但我最终还是弄明白了:

    根据标题或 .idl 的内容创建您的界面:

    [WinRTClassNameAttribute('Windows.Web.Http.HttpRequestMessage')]
    IHttpRequestMessage = interface(IInspectable)
    ['{F5762B3C-74D4-4811-B5DC-9F8B4E2F9ABF}']
      procedure Placeholder_ContentGet; safecall;
      procedure Placeholder_ContentPut; safecall;
      procedure Placeholder_HeadersGet; safecall;
      procedure Placeholder_MethodGet; safecall;
      procedure put_Method(value:IHttpMethod); safecall;
      procedure Placeholder_PropertiesGet; safecall;
      procedure Placeholder_RequestUriGet; safecall;
      procedure put_RequestUri(source: IUriRuntimeClass); safecall;
      procedure Placeholder_TransportInformationGet; safecall;
    end;
    

    然后在其下方添加一个 CoClass:

    THttpRequestMessage = class(TWinRTGenericImportI<IHttpRequestMessage>)
    end;
    

    然后可以这样使用:

    procedure TForm1.Button1Click(Sender: TObject);
    var
      req: IHttpRequestMessage;
    begin
      req := THttpRequestMessage.Create;
    end;
    

    【讨论】:

      猜你喜欢
      • 2016-03-15
      • 1970-01-01
      • 2013-09-24
      • 2013-10-06
      • 2015-02-28
      • 2017-02-13
      • 2021-11-30
      • 2017-05-03
      • 2017-10-30
      相关资源
      最近更新 更多