the value of a query string parameter may not cont

2020-02-15 08:57发布

问题:

Now I simplify the problem.

I try to directly copy and paste the query to confrim it use %3D instead of '='

    var xhrSNS = Ti.Network.createHTTPClient({
        onload :function(e) {
            Ti.API.info("test Post query:" + JSON.stringify(e));
            Ti.API.info(this.responseText); 
        },
        onerror : function(e){
            Ti.API.debug("test Create PlatForm Endpoint registerPush error:" + e.error);
            Ti.API.info(this.responseText); 

        }       
    });

        getUrl = "http://sns.ap-northeast-1.amazonaws.com?AWSAccessKeyId=AAAAAAAAAAAAAAA&Action=CreatePlatformEndpoint&PlatformApplicationArn=arn%3Aaws%3Asns%3Aap-northeast-1%3A776188326341%3Aapp%2FGCM%2Fmyapp&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=2016-04-03T15%3A05%3A51.465Z&Token=APA91bEiaB-902cRmwwgCwoqi2jRIJzzTIZNB7XduELuBKit_WF29tN5twrVW5t1BHpj07ARgwjzoc-I5xVur5K6I6ZQcnoErguUyi-VBHvuI5eY9HS4jq1J6KbIC05Etoe8indjpY9X&Version=2010-03-31&Signature=DzxQpP%2BcALS91C53eia6ZkBhxg3lQ32ctqiEmqKwwLA%3D";
        xhrSNS.open('GET',getUrl);
        xhrSNS.send();

Please see the last letter of getUrl, it surely use '%3D'.

But return is the same.

It makes a complaint that sentence include '=' delimiter.

[DEBUG] test Create PlatForm Endpoint registerPush error:400 : Bad Request
[INFO]  <ErrorResponse xmlns="http://webservices.amazon.com/AWSFault/2005-15-09">
[INFO]  <Error>
[INFO]  <Type>Sender</Type>
[INFO]  <Code>MalformedQueryString</Code>
[INFO]  <Message>AWSAccessKeyId=AAAAAAAAAAAAAAA&amp;Action=CreatePlatformEndpoint&amp;PlatformApplicationArn=arn%3Aaws%3Asns%3Aap-northeast-1%3A776188326341%3Aapp%2FGCM%2Fmyapp&amp;SignatureMethod=HmacSHA256&amp;SignatureVersion=2&amp;Timestamp=2016-04-03T15%3A05%3A51.465Z&amp;Token=APA91bEiaB-902cRmwwgCwoqi2jRIJzzTIZNB7XduELuBKit_WF29tN5twrVW5t1BHpj07ARgwjzoc-I5xVur5K6I6ZQcnoErguUyi-VBHvuI5eY9HS4jq1J6KbIC05Etoe8indjpY9X&amp;Version=2010-03-31&amp;Signature=DzxQpP%2BcALS91C53eia6ZkBhxg3lQ32ctqiEmqKwwLA= is not valid; the value of a query string parameter may not contain a '=' delimiter</Message>

-----------------------------adding until here-----------------

I am using Amazon SNS API

I made url like this it works well on browser.

http://sns.ap-northeast-1.amazonaws.com?AWSAccessKeyId=AAAAAAAAAAAAA&Action=CreatePlatformEndpoint&PlatformApplicationArn=arn%3Aaws%3Asns%3Aap-northeast-1%3A776188326341%3Aapp%2FGCM%2Fmyapp&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=2016-04-01T21%3A06%3A29.861Z&Token=APA91bEiaB-902cRmwwgCwoqi2jRIJzzTIZNB7XduELuBKit_WF29tN5twrVW5t1BHpj07ARgwjzoc-I5xVur5K6I6ZQcnoErguUyi-VBHvuI5eY9HS4jq1J6KbIC05Etoe8indjpY9X&Version=2010-03-31&Signature=Dt9tXa0Rjl%2Ff6YxZ4JaPfsm%2BT%2BMX03gS712nIKKekAI%3D

However if I try from Android.

This returns 400 bad request.

<ErrorResponse xmlns="http://webservices.amazon.com/AWSFault/2005-15-09">
<Error>
<Type>Sender</Type>
<Code>MalformedQueryString</Code>
<Message>AWSAccessKeyId=AAAAAAAAAAAAA&amp;Action=CreatePlatformEndpoint&amp;PlatformApplicationArn=arn%3Aaws%3Asns%3Aap-northeast-1%3A776188326341%3Aapp%2FGCM%2Fmyapp&amp;SignatureMethod=HmacSHA256&amp;SignatureVersion=2&amp;Timestamp=2016-04-01T21%3A06%3A29.861Z&amp;Token=APA91bEiaB-902cRmwwgCwoqi2jRIJzzTIZNB7XduELuBKit_WF29tN5twrVW5t1BHpj07ARgwjzoc-I5xVur5K6I6ZQcnoErguUyi-VBHvuI5eY9HS4jq1J6KbIC05Etoe8indjpY9X&amp;Version=2010-03-31&amp;Signature=Dt9tXa0Rjl%2Ff6YxZ4JaPfsm%2BT%2BMX03gS712nIWUekAI=
 is not valid; the value of a query string parameter may not contain a '=' delimiter</Message>
</Error>
<RequestId>5b40d988-af34-577a-8839-96f04a217dec</RequestId>
</ErrorResponse>

I think

the value of a query string parameter may not contain a '=' delimiter

is the cause of problem though, I cant figure out how to fix it.

The same code works on iPhone.

it doesn't work only from android.

I made URL strings from this function

var array = {
    PlatformApplicationArn : Ti.App.global.androidArn
};
awsObj = getSignature("CreatePlatformEndpoint",date,awsUrl,event.registrationId,array);
    var getUrl = "http://" + awsUrl + '?' + awsObj.str_para + "&Signature=" + awsObj.encodedString;
Ti.API.info('GETurl :' + getUrl);
xhrSNS.open('GET',getUrl);


function getSignature(action,date,awsUrl,token,array){
    Ti.include('/jssha/jssha256.js');

    var base = {
        Action:action,
        AWSAccessKeyId : Ti.App.global.awsAccessKey,
        SignatureMethod : "HmacSHA256",
        SignatureVersion :2,
        Token: token,
        Timestamp : date,
        Version : "2010-03-31",
    };
    para = arrayMerge(array,base);

    var para_array = [];

    for(var pname in para){
        para_array.push(pname + "=" + encodeURIComponent(para[pname]));
    }
    para_array.sort();

    var str_para = para_array.join('&');
    var str_signature = "GET" + "\n" + awsUrl + "\n" + "/" + "\n" + str_para;

    console.log("str_signature:" + str_signature);

    HMAC_SHA256_init(Ti.App.global.awsSecretKey);
    HMAC_SHA256_write(str_signature);
    var array_hash = HMAC_SHA256_finalize();

    var str_hash = "";
    for (var i = 0; i < array_hash.length; i++) {
        str_hash += String.fromCharCode(array_hash[i]);
    }

    var awsObj = new Object();
    awsObj.encodedString = encodeURIComponent(base64encode(str_hash));

    Ti.API.info("awsObj.encodedString:" + awsObj.encodedString); // I have confirmed encodedString is correct here.
    awsObj.str_para = str_para;
    return awsObj;
}

回答1:

URL in browser: Signature=Dt9tXa0Rjl%2Ff6YxZ4JaPfsm%2BT%2BMX03gS712nIKKekAI%3D

URL in Android: Signature=Dt9tXa0Rjl%2Ff6YxZ4JaPfsm%2BT%2BMX03gS712nIWUekAI=