如何设置授权HTTP标头的Javascript [英] How to Set Authorization HTTP Header with Javascript

查看:482
本文介绍了如何设置授权HTTP标头的Javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用OAuth在API库和API要求Authorization头为每个请求明确设置。

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

我熟悉的setRequestHeader方法,使用它像:

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"

我如何正确设置使用setRequestHeader这种格式的授权头?谢谢!

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

推荐答案

使用OAuth的JavaScript库。它的设置建立这些签署的OAuth头为你...

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

HTTP://oauth.google$c$c。 COM / SVN / code / JavaScript的/

这篇关于如何设置授权HTTP标头的Javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆