如何使用jquery以api key(auth)作为标头发送api url? [英] how to send api url with api key(auth) as header using jquery?

查看:135
本文介绍了如何使用jquery以api key(auth)作为标头发送api url?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

资源网址

https://auspost.com.au/api/postage/parcel/domestic/weight

标题

auth -key
需要


获取

https://auspost.com.au/api/postage/parcel/domestic/weight.{format }



i无法使用api链接发送标题。

plsease举个例子。

解决方案

使用jQuery ajax方法,您可以通过两种方式设置标题 - 这些标题将随请求一起发送...

1。

 


.ajax({
type:' POST'
url:' https: //auspost.com.au/api/postage/parcel/domestic/weight'
标题:{
< span class =code-string> auth-key: value
// 根据需要提供更多信息
}
});



2。

 


.ajax({
type:' POST'
url:' https://auspost.com.au/api/postage/parcel/domestic/weight'
beforeSend: function (xhr){
xhr.setRequestHeader( auth-key value);
// 根据需要提供更多信息
}
});


Resource URL
https://auspost.com.au/api/postage/parcel/domestic/weight
Headers
auth-key
required
GET
https://auspost.com.au/api/postage/parcel/domestic/weight.{format}

i can't able to send header with api link.
plsease give some example.

解决方案

With jQuery ajax methods you have two ways to set headers - those headers will be sent with the request...
1.


.ajax({ type: 'POST', url: 'https://auspost.com.au/api/postage/parcel/domestic/weight', headers: { "auth-key":"value" // more as you need } });


2.


.ajax({ type: 'POST', url: 'https://auspost.com.au/api/postage/parcel/domestic/weight', beforeSend: function(xhr) { xhr.setRequestHeader("auth-key", "value"); // more as you need } });


这篇关于如何使用jquery以api key(auth)作为标头发送api url?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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