Loading content from external site (Avoiding CORS) - Forum

Forum Navigation
You need to log in to create posts and topics.

Loading content from external site (Avoiding CORS)

After reading this interesting article, I have tested this free proxy to avoid CORS while loading external site text content from VisualNEO Web apps and it works really well.

For example if you want to get the HTML code from google.es and store it in a variable this won't work:

FileToVar "https://google.es" [MyVar]

But if you use this instead, it will work:

FileToVar "https://cors-anywhere.herokuapp.com/https://google.es" [MyVar]

Just prepend the proxy url to the url you want to load into the variable.
This will work with any .txt, .json, .xml file or while trying to connect to an API.

I'm now searching on how to create our own proxy using a .php script.

I hope you will find this as useful as I do :)

UPDATE 21/02/25: This free proxy doesn't work anymore. Please read below for alternatives.

 

Uploaded files:
  • You need to login to have access to uploads.
Vadim and asmat have reacted to this post.
Vadimasmat

Thank you luishp...

Welcome back @asmat :)

This is a very simple PHP proxy script:

<?php
header("Access-Control-Allow-Origin: *");
$url = (isset($_GET['url'])) ? $_GET['url'] : false;
if(!$url) exit;
set_error_handler("warning_handler", E_WARNING);
//header('Content-Type: text/html');        //uncomment this to send auth creds
$string = file_get_contents($url, false);
echo $string;
restore_error_handler();
function warning_handler($errno, $errstr) { 
  header('Content-Type: text/plain');
  echo $errstr;
}
exit;
?>

I have installed a copy in this server (don't use it for production, just for testing). Usage:

FileToVar "https://visualneo.com/proxy/?url=https://google.es" [MyVar]

This open up a lot of possibilities for web scrapping :)
More to come.

Regards.

asmat has reacted to this post.
asmat

Very Good and Thank you luishp

@luishp

This worked on a text file on my (http) website .. from my VisualNEOWeb App resident on my C: drive.

It will make testing Apps that 'dynamically load plain text, HTML text/templates, Listbox items and JSON key:value pairs' a lot quicker.

Just remember that FileToVar is an asynchronous process ... when I followed this command with an AlertBox, I kept getting 'undefined' for the variable ... so it should be used in conjunction with the OnLoadSuccess and OnLoadError commands.

Thanks.

 

 

Vadim has reacted to this post.
Vadim

@luishp

Por favor me puedes indicar como debo hacer para poder instalar tu pequeño script de proxy en mi servidor.

Que nombre debe tener ese archivo php que muestras en el script?

cual es la ruta que deberia estar en mi servidor (https://globaldima.com....)

Desde ya un millon de gracias

@joferar333 el nombre que tu quieras, por ejemplo "proxy.php" (yo lo he llamado index.php para que sea el que el servidor coge por defecto en la carpeta). Solo recuerda el nombre que le has dado para poderlo invocar después en la URL.
La ruta, la que tu quieras. Puedes subirlo al directorio raíz, a una carpeta, a un subdominio o donde prefieras.

Ejemplo:

FileToVar "https://globaldima.com/proxy.php?url=https://google.es" [MyVar]