使用标题参数消费WEP API
我写了Web API并与Postman一起消费,在标题中有变量及其价值。 参数名称是Apikey,我在Postman中加载了值,因此Web API返回答案是成功的。 但是我无法与jQuery一起食用, 它返回401代码。我尝试了底部代码,但没有起作用。
$.ajax({
url : 'http://XXX:8020/getPer/1010',
dataType : "jsonp",
headers: { "Content-Type":"application/json","Accept": "application/json" },
type : 'GET',
contentType: "application/json",
beforeSend : function( xhr ) {
xhr.setRequestHeader( "ApiKey", "xxxyyyzzz" );
},
success : function (data) {
console.log(data);
},
error : function (data, errorThrown) {
alert(3);
}
});
我也将邮局结果放在底部。
I wrote web api and consume it with postman succesfully, in header there is variable and its value.
Parameter name is ApiKey and i loaded value in the postman, So web api return answer succesfully.
But I could not consume with jquery,
It returns 401 code. I tryed bottom code but it is not worked.
$.ajax({
url : 'http://XXX:8020/getPer/1010',
dataType : "jsonp",
headers: { "Content-Type":"application/json","Accept": "application/json" },
type : 'GET',
contentType: "application/json",
beforeSend : function( xhr ) {
xhr.setRequestHeader( "ApiKey", "xxxyyyzzz" );
},
success : function (data) {
console.log(data);
},
error : function (data, errorThrown) {
alert(3);
}
});
I put postman result also in bottom.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Postman支持为多种语言生成代码。
在此处查看
dothttp 也有类似的选择,并且与开发人员也有类似的选择。
谢谢
Postman has support to generate code for multiple languages.
check here
Dothttp also has similar option and works well with developers.
Thanks