Jump to content

How To Read A Value Returned By URL In A TUniUrlFrame?


Frederick

Recommended Posts

I set the URL property of a TUniURLFrame to a URL that returns a single value. The value can be seen in the TUniURLFrame.

The following event is not fired.

procedure TfrmShare.UniURLFrame1AjaxEvent(Sender: TComponent; EventName: string;
  Params: TUniStrings);
begin
   showmessage(params.Text);
end;

How do I read the value returned by the URL?

--
Frederick
(UniGUI Complete - Professional Edition 1.90.0.1562)
 

Link to comment
Share on other sites

6 minutes ago, Sherzod said:

Do you have to use UrlFrame?

No. My objective is to call the URL, get a response value and save/use it.

I am open to using any other method to achieve the result. Since I am using UniGUI, I thought of using its components first.

Link to comment
Share on other sites

1 hour ago, Frederick said:

No. My objective is to call the URL, get a response value and save/use it.

I am open to using any other method to achieve the result.

Yes, you need to use a server solution, for example using IdHTTP.

Link to comment
Share on other sites

hello, try with this

      UniSession.AddJS  (
                    '  new Promise(function(resolve, reject) {' +
                    '  const xhttp = new XMLHttpRequest();'
                    + '  xhttp.open("GET", ''' + fURL + TRIM (cmd) + ''', false);'
                    + '  xhttp.send(null);'

                    + '       var sRes = xhttp.responseText;'
                    + '       if (sRes != "") {'
                    + '            ajaxRequest (' + myMemo.JSName
                    + '                        , "FiscalAnswer", ["_value=" + "" + sRes + "","_cmd=" + "' + sCMD + '"]);'
                    + '       };' //if sRes <> ''
                    + '       document.getElementById("' + myMemo.JSName + '_id").innerHTML = this.responseText;'
                    + '});'//end Promise

        );


         this open url with parameters and get result in ajaxrequest and memo 

Link to comment
Share on other sites

1 hour ago, irigsoft said:

const xhttp = new XMLHttpRequest();'
                    + '  xhttp.open("GET", ''' + fURL + TRIM (cmd) + ''', false);'
                    + '  xhttp.send(null);'

This will also be blocked by CORS policy.

Link to comment
Share on other sites

2 hours ago, Sherzod said:

Yes, you need to use a server solution, for example using IdHTTP.

Thanks for the tip.

The following code works for me:-

      idHttp:=TIdHttp.Create(NIL);
      try
         showmessage(idHttp.Get(<url>));
      finally
         idHttp.Free;
      end;
 

Link to comment
Share on other sites

1 hour ago, irigsoft said:

this open url with parameters and get result in ajaxrequest and memo 

Thanks for the code.

However, I am getting no response from the URL. Maybe, the URL just returns a string value and your code does nothing for it or like Sherzod mentioned, the code is not being executed or allowed to execute because of a blocked CORS policy?

Link to comment
Share on other sites

35 minutes ago, Oliver Morsch said:

If you have the target server under control, then you can configure CORS there...

It is a vendor-owned SMS gateway server so configuration control is out of the question.

I am curious however. If Indy's TIdHttp or similar components can access the server and get a response code, why is it necessary to use complicated code and fiddle with CORS?

Link to comment
Share on other sites

9 minutes ago, Oliver Morsch said:

CORS is for security. So that no website can access the content of a foreign website.

Since the SMS gateway is a service site, the vendor allows anyone to access it. In fact, their API is published.

Did they configure CORS to block access?

Link to comment
Share on other sites

16 minutes ago, Oliver Morsch said:

I think CORS is normally active by default. Maybe they can confirure your IP to be allowed.

The SMS gateway does have a IP whitelist option. If I specify one or more IP addresses to be whitelisted, only these IP addresses can access the gateway. I suppose this is the CORS configuration equivalent.

Currently, I did not specify anything. So, any URL calls from my computer to the gateway should go through.

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...