简体   繁体   中英

401 Authorization Required Error in Using Web API

I am a newbie in the use of Web-API.have a web-API by using which i can get response in Json format.I am using this API in jsp usinh jquery Ajax. Here is the structure of web-API .

http://pnrbuddy.com/api/check_pnr/pnr/<10 digit PNR number>/format/<xml|json> / pbapikey / <your public api key> / pbapisign(private key) / <HMAC signature> 

Please see the API parameters names and their meaning.

I am trying to use this by passing values as..

http://pnrbuddy.com/api/check_pnr/pnr/1234567890/format/json/pbapikey/c70a600b160e9a1fd4c6aa772e63e612/pbapisign/71988fc2bacfe995e96e65c1cbfed3dc2ba613c8

Buu while executing i am getting error as ..

401 Authorization Required.

and In the Response of firebug.this message..

Reload the page to get source for: http://pnrbuddy.com/api/check_pnr/pnr/1234567890/format/json/pbapikey/c70a600b160e9a1fd4c6aa772e63e612/pbapisign/71988fc2bacfe995e96e65c1cbfed3dc2ba613c8

How to resolve this .

My HMAC generation code.

            String mykey = "Private Key";
    String test = "pnrjson6b17f33e25e2d8197462d1c6bcb0b130";
    try {
        Mac mac = Mac.getInstance("HmacSHA1");
        SecretKeySpec secret = new SecretKeySpec(mykey.getBytes(),
                "HmacSHA1");
        mac.init(secret);
        byte[] digest = mac.doFinal(test.getBytes());
        for (byte b : digest) {
            System.out.format("%02x", b);
        }
        System.out.println();
    } catch (Exception e) {
        System.out.println(e.getMessage());
    }

My new API URL values..

http://pnrbuddy.com/api/check_pnr/pnr/1234567890/format/json/pbapikey/6b17f33e25e2d8197462d1c6bcb0b130/pbapisign/ebb4279d9b8cc3e011a7d7a46248c4ac456a6ca3

Still i am getting same authorization error. Why?

Here is my client side code.

<script type="text/javascript">
        $(document).ready(function () {
            $("#click").click(function () {

                $.ajax({
                    type: "POST",
                    url: "http://pnrbuddy.com/api/check_pnr/pnr/1234567890/format/json/pbapikey/6b17f33e25e2d8197462d1c6bcb0b130/pbapisign/8dd7f570509ab9b7d27cc182982d49ca63fb45d6",
                    contentType: "application/json",
                    async: false,
                    success: function (data) {
                        $("#response").html(data.d);
                    }

                });
            });
        });
    </script>


</head>
<body>
    <button id="click">GetPNR Status</button>
    <div id="response"></div>
</body>

Firstly I think you need to register as a developer in pnrbuddy(steps are in my comments). You need to use your own keys to access the api.

And then refer this: http://pnrbuddy.com/hauth/api?page=keys

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM