简体   繁体   中英

How to Set Authorization HTTP Header with Javascript

I'm using oauth in an API library and the API requires that the Authorization header be explicitly set for each request.

I'm familiar with the setRequestHeader method, using it like:

this.request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");

However, I'm not sure how to properly set the Authorization header, since it has so many parameters. An example of what the header needs to look like is:

Authorization: OAuth realm="",oauth_version="1.0",oauth_consumer_key="consumer",oauth_token="foo",oauth_timestamp="timestamp",oauth_nonce="ononce",oauth_signature_method="PLAINTEXT",oauth_signature="osig"

How do I properly set the Authorization header in this format using setRequestHeader? Thanks!

Use the OAuth javascript library. It's setup to build those signed OAuth headers for you...

http://oauth.googlecode.com/svn/code/javascript/

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