3

I need to download a file from a web service which uses basic authentication. This means I need to add an authorization header to the request. I know how to do this using jQuery Ajax, but I CANNOT use Ajax since I need to download a file from the url and Ajax requests cannot download files to disk.

How can I set the authorization header before I do window.location = url ?

I searched the web, but everything I find is about jQuery Ajax which I cannot use.

Jeroen
  • 185
  • 1
  • 1
  • 11
  • "How can I set the authorization header before I do window.location = url" You don't. You basically are just typing the url in the browser addressbar and hit enter AFAIK – PeeHaa Jun 13 '13 at 12:05

1 Answers1

0

You can put them in the URL:

https://user:password@host/path?query

Note that browsers may block this for security reasons.
(These URLs are frequently used with usernames like google.com for phishing attacks)

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964
  • Thanks for your answer. When I use Chrome, using the url you supplied, there's no authorization header in the request. IE won't even fire the request and gives the message 'SCRIPT14: A security problem occurred.' Is there any other way to do this, otherwise it's back to the drawing table I suppose. – Jeroen Jun 13 '13 at 12:35
  • 1
    About IE: http://support.microsoft.com/kb/834489 Internet Explorer does not support user names and passwords in Web site addresses (HTTP or HTTPS URLs). – Jeroen Jun 13 '13 at 12:43
  • I mark this as the answer since it basically is. But anyone reading this should take note of the comments above. – Jeroen Jun 13 '13 at 13:19