使用WebView / EdgeHTML发送POST请求

我目前正在根据以下答案尝试使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”过程中使用它?

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

hy124513 回答:使用WebView / EdgeHTML发送POST请求

根据official docs,我们可以在C#中使用如下方法:

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

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

,

如果您已经对接口有所了解,那么答案很简单。但我最终确实弄清楚了:

根据标题或.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;
本文链接:https://www.f2er.com/3101398.html

大家都在问