使用标题参数消费WEP API

发布于 2025-01-29 07:13:13 字数 749 浏览 3 评论 0原文

我写了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);
    }
});

我也将邮局结果放在底部。

succeslowslowned frolpostman

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.

SuccesfullyReturnedFromPostman

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

神也荒唐 2025-02-05 07:13:13

Postman支持为多种语言生成代码。

在此处查看

dothttp 也有类似的选择,并且与开发人员也有类似的选择。

谢谢

Postman has support to generate code for multiple languages.

check here

Dothttp also has similar option and works well with developers.

Thanks

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文