如何设置授权HTTP标头的Javascript如何设置、HTTP、Javascript

2023-09-10 16:54:25 作者:四裤全输

我使用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的/