简体   繁体   中英

Specifying HTTP headers in anchor tag

I'm writing some code to drag files from a web app to the desktop using Chrome's support for anchor element dragging.

Unfortunately, some of the file links require more than a simple GET - they require a GET with an HTTP authorization header.

One strategy would be to proxy it through another server that makes the actual GET request and forwards the response back to the client, like so:

<a href="http://myproxy.com?url=http://example.com/file.txt&Authorization=blah">

I'm trying to avoid that since I want this to be a purely client-side implementation, so I want to pick the brains of SO developers and see if anyone has a better solution that doesn't involve a proxy.

Any help would be appreciated.

You can specify the username and password in the URL:

<a href="http://username:password@example.com/file.txt">

I don't think there's any way to have more control over the headers that are sent.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM