Home > develop, web > Safe and Dirty Remote XMLHttpRequest

Safe and Dirty Remote XMLHttpRequest

August 27th, 2008 Leave a comment Go to comments

Safe and Dirty Remote XMLHttpRequest Sometimes we need XMLHttpRequest work on diferents domains (cross domains) a simple solution, you need JavaScript and Perl:

The XMLHttpRequest(); example:

var req = new XMLHttpRequest() // IE7, Firefox, Safari, Opera
req.open('GET', 'http://localhost/cgi-bin/remote.pl?url='+url, false);
req.send(null);

To make the remote request work, use remote.pl:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#!/usr/bin/perl
use LWP::UserAgent;
use CGI qw(:standard);
print "Content-type: text/plain\n";
my $url = param ('url');
$ua = LWP::UserAgent->new;
$ua->agent("Mozilla/8.0");
$req = HTTP::Request->new(GET => $url);
$req->header('Accept' => 'text/html');
$res =$ua->request($req);
if ($res->is_success) {
	$page = $res->content;
} else {
	$page = "error";
} print $page;

This is only a example:

The remote.pl could be much better implement (GET and POST methods, params and theirs values).

Categories: develop, web Tags: ,
  1. September 11th, 2008 at 17:02 | #1
    Surfing Internet Explorer 7.0 Internet Explorer 7.0 on Windows Vista Windows Vista

    que tal?, solo escribia para felicitarte por tu sitio

  2. October 15th, 2008 at 15:27 | #2
    Surfing Firefox 3.0 Firefox 3.0 on GNU/Linux GNU/Linux

    If possible please avoid using yellow color for the text – its unreadable on the white background.

    By the way, this method is called ‘using a proxy’ – very useful in some situations. But you have to be careful using it – it can open XSS vulnerabilities on your site.

  1. No trackbacks yet.

Switch to our mobile site