Jump to content
IElite

HttpRequest not working outside of SMS

Recommended Posts

I m using a TW3HttpRequest to load a JSON file

procedure TForm1.InitializeObject;
begin
  inherited;
  {$I 'Form1:impl'}
  fHttp := TW3HttpRequest.Create;
  fHttp.OnDataReady:= HandleHttpDataReady;
end;

procedure TForm1.InitializeForm;
begin
  inherited;
  // this is a good place to initialize components
  fHttp.Get('res\data.json');
end;



procedure TForm1.HandleHttpQuizDataReady(Sender:TW3HttpRequest);
var y: integer;
begin
  fJSONStr:= Sender.ResponseText;
  gData:= JSON.parse(fJSONStr);
 // more code here
end;

Everything works great s long as I am running it under SMS using default browser.

If I try to load the index.html into a browser outside of SMS, the code does not work. the JSON file never loads. The OnDataReady never gets called.

 

 

Share this post


Link to post
Share on other sites

Hi @IElite, are you trying to run this index.html from the file system without a web server? If that's the case then this will fail as the browser will not allow you to access local files. If that's not the case and you are still running the SMS web server and just trying to access the file from an alternate browser, then can you detail your steps and ip address/port used  to access the file as it works fine for me here in chrome.

Note: I'm assuming the below was a transcription error and it was actually meant to be "HandleHttpQuizDataReady"

fHttp.OnDataReady:= HandleHttpDataReady;

Share this post


Link to post
Share on other sites

"Note: I'm assuming the below was a transcription error and it was actually meant to be "HandleHttpQuizDataReady"

Yes, transscibe error

How do i set up a SMS webserver to make it work?

Share this post


Link to post
Share on other sites

I uploaded it to our website server

fHttp.Get('https://www.<ourdomain>.org/data/data.json');

and I gives me the error

Uncaught SyntaxError: Unexpected end of JSON input  [line #1]

 

But I dont get an error If I do

fHttp.Get('res\data.json');

Share this post


Link to post
Share on other sites

Can you verify that your data.json is valid json?

If you comment out the json.parse line and log the data to the console does the error still occur?

How are you verifying that ondataready doesn't get called?

Sorry if these questions seem obvious but your minimal example doesn't answer them.

Share this post


Link to post
Share on other sites

From a security perspective (and don't quote me), I don't think the file contents of the image are available to the user so they couldn't use javascript to send the file to a malicious user. On the other hand, the get request would provide this data which the user could use for any purposes.

Also, the file host resolves to null with the htmlrequest, if you open a file directly from the filesystem, which breaches the browsers Cross Origin policy as the Get Request is attempting to connect to localhost.

Anyone with better knowledge of HTML security or terminology should feel free to jump in and correct/expand upon the above answer but I "think" that is the main reason.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×