Jump to content

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.

 

 

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

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...