You are not logged in.
Hi ab,
I've used mormot2 as working toolbox.
I've making use of THttpServer as a server, while using TWebBrowser as client.
They can work around very well.
When I fetch some data from THttpServer with HttpGet, Uri.Address was truncated before blank.
I've make an additional step, which might be a default behavior of HttpGet.
var
uri: TUri;
begin
if not uri.From(aUrl) then Exit;
HttpGet(Format('%s://%s:%s/%s',[uri.Schema, uri.Server, uri.Port, UrlEncode(uri.Address)]));
end;
Last edited by uian2000 (2021-02-23 08:52:55)
Offline
Address part of uri was not encoded.
when I make a request like this.
HttpGet('http://127.0.0.1/hello world');
Server side Ctxt.Url will be
'/hello'
But if it was made by a TWebBrowser.Navigate(), that Ctxt.Url will be
'/hello%20world'
Last edited by uian2000 (2021-02-23 16:54:03)
Offline
Try this:
const
URL_TEMPLATE = 'http://127.0.0.1/%';
var
content: SockString;
begin
content := HttpGet(StringToAnsi7(FormatString(URL_TEMPLATE, ['hello world'])));
...
With best regards
Thomas
Offline
As I understand it, he wants the url passed to the HttpGet method to be encoded automatically.
But this would not be correct, because if the url is already encoded it will be encoded twice.
The correct thing is to leave the url encode for the application and not for the HttpGet and related methods.
Offline
thx @tbo, will try your approach.
thx @ab, I've post a sample here
Pastebin-uMain.pas.
Pastebin-uMain.dfm.
pls check it.
Delphi XE,Windows 7 X64
thank you.
Last edited by uian2000 (2021-02-24 05:30:50)
Offline
I still don't get it.
The URI should be properly encoded on client side to work.
If you keep spaces in the URI, then it won't be correct for sure.
HttpGet() don't make any correction, it just passes the supplied value, and 'http://127.0.0.1/Hello World' is not a valid URL.
Offline
Because TWebBrowser.Navigate() automatically executes UrlEncode, I thought HttpGet should behave the same way.
If httpGet itself is positioned to simply make http requests, that's right.
Offline
We should ALWAYS UrlEncode an user input. TWebBrowser.Navigate() simulates the browser address line where user input address, so it UrlEncode it
In opposite to this HttpGet is called by developer, if developer know address is come from used input he MUST UrlEncode it, if address is a constant in sources and not contains special characters - not.
If HttpGet will UrlEncode address this brake existed code in case argument is already UrlEncoded (as it should be)
So the current behavior is correct
Offline
Thank you @mpv, your explanation is very convincing.
Thank you @ab, you've build this awesome framework.
Offline