0

I'm currently trying to get EdgeHTML/WebView to work based on this answer: Using WebView (EdgeHTML) in Delphi / C++ Builder

Copying the code and running it works just fine.

But now I'm trying to add the "NavigateWithHttpRequestMessage" procedure, so that I can send POST requests and have to realize that I've got no clue whatsoever how I'm supposed to create the object for its parameter.

This is the description of the procedure: https://learn.microsoft.com/en-us/uwp/api/windows.web.ui.iwebviewcontrol.navigatewithhttprequestmessage

It tells me that the parameter is of type "HttpRequestMessage".

I've downloaded the Windows 10 Kit and found the Windows.Web.Http.idl and this Interface for "HttpRequestMessage" inside:

[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);
}

I can translate this to an Interface in Delphi just like NineBerry did with other interfaces in the link above. (Or at least with dummy procedures. Not really sure about the types of the parameters yet.)

But how do I create an object from that so that I can use it with the "NavigateWithHttpRequestMessage" procedure?

Any help or even pointers into the right direction would be much appreciated.

user3437976
  • 101
  • 1
  • 6

2 Answers2

0

According to the official docs, we can use the method like this in C#:

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

I can't find Delphi examples. You could refer to the C# examples and try to convert it to Delphi.

Yu Zhou
  • 11,532
  • 1
  • 8
  • 22
  • Yes, that's the goal. But where is that HttpRequestMessage class coming from? The most I have is that interface and I can't create an object from that. In c# that class is in "using Windows.Web.Http;", but where is it coming from in Delphi? – user3437976 Nov 15 '19 at 08:43
0

The answer is rather simple if you know anything about interfaces already. But I did figure it out eventually:

Create your Interface based on what the header or the .idl says:

[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;

Then add a CoClass right beneath it:

THttpRequestMessage = class(TWinRTGenericImportI<IHttpRequestMessage>)
end;

This can then be used like this:

procedure TForm1.Button1Click(Sender: TObject);
var
  req: IHttpRequestMessage;
begin
  req := THttpRequestMessage.Create;
end;
user3437976
  • 101
  • 1
  • 6