Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6763441
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:28:35+00:00 2026-05-26T14:28:35+00:00

Hi I’m trying to convert the PHP Code example for an AWIS request found

  • 0

Hi I’m trying to convert the PHP Code example for an AWIS request found here:

http://aws.amazon.com/code/AWIS/402

to javascript / jquery. I feel like I’m very close, but I’m getting an “unauthorized” 401 response. I would love to get this up and running, and I was wondering if anyone could tell me what I’m doing wrong, or point me in the direction of an example using javascript.

<html>
    <head>
        <title>AWIS</title>
        <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
        <script type="text/javascript" src="http://crypto-js.googlecode.com/files/2.3.0-crypto-sha256-hmac.js"></script>
        <script type="text/javascript" src="http://crypto-js.googlecode.com/files/2.3.0-crypto-min.js"></script>
    </head>
    <body>
        <div id="output"></div>
        <script>
        var actionName = 'UrlInfo';
        var responseGroupName = 'Rank,LinksInCount';
        var serviceHost = 'awis.amazonaws.com';
        var count = 10;
        var startNum = 1;
        var sigVersion = '2';
        var hashVersion = 'HmacSHA256';
        var accessKeyID = 'XXXAJA664T37BDNPSXXX';
        var accessKey = 'XXXoImq0sZ4J/vYRewLuNjPFXYQ809DfLmzcpXXX';
        var site = 'http://site.com';

        function getURLInfo(){
            var queryParams = buildQueryParams();
            var sig = generateSignature(queryParams);
            var requestURL = 'http://' + serviceHost + '/?' + queryParams + '&Signature=' + sig;
            console.log('requestURL:' + requestURL);

            $.ajax({
                type: 'GET',
                url: requestURL,
                dataType: 'xml',
                crossDomain: true,
                error: function(jqXHR,textStatus, errorThrown){
                    console.log(textStatus + "|" + errorThrown)
                },
                success: function(data, textStatus, jqXHR){
                    console.log(data);
                }
            });


        }

        function ISODateString(d){
          function pad(n){return n<10 ? '0'+n : n}
          return d.getUTCFullYear()+'-'
              + pad(d.getUTCMonth()+1)+'-'
              + pad(d.getUTCDate())+'T'
              + pad(d.getUTCHours())+':'
              + pad(d.getUTCMinutes())+':'
              + pad(d.getUTCSeconds())+'.000Z'
        }   

        function getTimeStamp(){
            var d = new Date();
            var now = ISODateString(d);
            //var hardcoded_time = "2011-10-28T16:33:03.000Z"; //USE THIS TO TEST BETWEEN SAMPLE PHP AND JS
            return now;
        }

        function buildQueryParams(){
            var params = {};
            params.AWSAccessKeyId = accessKeyID;
            params.Action = actionName;
            params.Count = count;
            params.ResponseGroup = responseGroupName;
            params.SignatureMethod = hashVersion;
            params.SignatureVersion = sigVersion;
            params.Start = startNum;
            params.Timestamp = getTimeStamp();
            params.Url = site;

            paramString = $.param(params);
            return paramString;
        }

        function generateSignature(sigParams){
            var sign = "GET\n" + serviceHost + "\n/\n" + sigParams;
            console.log("SIGN: \n" + sign);
            var sigHash = Crypto.HMAC(Crypto.SHA256, sign, accessKey, { asString: true });
            console.log("HMAC:" + sigHash);
            var sigBytes = Crypto.charenc.Binary.stringToBytes(sigHash);
            var sig64 = Crypto.util.bytesToBase64(sigBytes);
            console.log("BASE 64: " + sig64);
            var sigEnc = encodeURIComponent(sig64);
            console.log("ENCODED URL: " + sigEnc)
            return sigEnc;
        }

        function awisResponse(response){
            console.log(response);
        }

        getURLInfo();

        </script>
    </body>
</html>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T14:28:35+00:00Added an answer on May 26, 2026 at 2:28 pm

    [UPDATE]
    Derp. I think I pointed out several outstanding issues here, but must admit I still wasn’t quite catching onto the problem of cross site.

    The final piece of the puzzle is using a proxy so PHP can get the xml. So this isn’t a javascript only solution, but mostly it is:
    http://benalman.com/projects/php-simple-proxy/
    [/UPDATE]

    I’d prefer you don’t give up on this for the wrong reason. You’ll remember that the X in AJAX stands for XML 🙂

    So two ideas based on duskwuff’s commments.

    • You surely can parse XML with javascript. The function you are using already supports ‘xml’ as a datatype.
    • It seems like you are going wrong with the callback part. You can pass a callback function to either complete, success, and/or error.

    Here’s the code:

    $.ajax({
        type: 'GET',
        url: requestURL,
        dataType: 'xml',
        error: function(jqXHR, textStatus, errorThrown){
            console.log(textStatus);
        },
        success: function(data, textStatus, jqXHR){
            console.log(data);
        }
    });
    

    Your more pressing problem is in the authentication, but perhaps you will be able to get more details now using the error function and it’s errorThrown argument.

    My recommendation is to see if you can get the URL generated in another context and compare that to what you have to see if you’re doing it right (it’s been a few months, but I thought I remember there being an amazon tool that generated the request URL for you).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
this is what i have right now Drawing an RSS feed into the php,
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I am trying to loop through a bunch of documents I have to put
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.