Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

POST to password protected URL?

I am working on a project that requires me to POST some data to a url that requires a username and password for access. How do I build the URL so that it automatically logs into the system?

$.ajax({
    url: "https://xxxxxxx",
    type: "POST",
    data: "___PUT_BODY___="+file+"&file="+time,
})
like image 855
Andrew Avatar asked Oct 19 '10 17:10

Andrew


2 Answers

If the page uses "Basic" HTTP authentication (the kind where the browser opens a little dialog window asking for a username and password), you can simply do:

https://username:[email protected]/

If the site has a login form embedded on the page somewhere, then the login information doesn't go in the URL. You would have to simulate submitting that form (by generating a similar AJAX request specifically for logging in).

like image 168
VoteyDisciple Avatar answered Oct 29 '22 02:10

VoteyDisciple


Read the funny manual

Also, don't make your query string the way it comes out in the URI bar, make it an object. Also, semi-colon goes at the end of that statement.

$.ajax({
    url: "https://example.com",
    type: "POST",
    data: {
            "___PUT_BODY___="   : file, 
            "&file="            : time
          },
    password : "theP4s$w0rD!",
    username : "Bob's big bad world of HTTP Auth"

});
like image 21
Incognito Avatar answered Oct 29 '22 04:10

Incognito