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,
})
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).
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"
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With