tags:

views:

20

answers:

2

Hello,

I'm wondering if anyone knows a javascript library where I could remotely login to a site, then browse pages upon logging in.

This is very easy with php's curl but I'm wondering if there is a javascript equivalent where I can execute multiple remote url's under a single http session.

Basically what I'm looking to do is post a username/password to one of my sites and then immediately post some other commands to a different url (same remote domain) using the authenticated session.

I haven't come across anything like this yet so I'm wondering if anyone can point me in the direction (if it's even possible). Can definitely be HTML5.

+1  A: 

Due to same origin policy restrictions in browsers this is not possible using javascript. You need a server side script that will act as a bridge between your site and the remote sites. Then talk to this local script using AJAX.

Darin Dimitrov
A: 

There are some techniques available to bypass the same origin policy:

If you don't need to read the response of your POST calls, you can create a FORM by javascript with an action to any url (not limited to the same origin policy) like in this question: http://stackoverflow.com/questions/298745

But this means you rely only on session cookies for the security, this is open for XSS attacks.

As you own the other domain site, you could develop a small service that returns a JSON with the data you need, and use the JSONP technique, eg:

<script src="http://otherdomain/curl?url=page.html&amp;callback=cb"&gt;
</script>

May be you could signin before using the POST technique above and sending a secret token that you reuse in the url to improve the security.

And finally there is a way to act/read on other pages using a bookmarklet.
The idea is to inject in the other domain's page a script that can run with all the privileges, and send back information to your domain.
But this requires a manual action (click a link or a browser bookmark)

Mic