现在我简化了问题。
我尝试直接复制并粘贴查询以确认它使用%3D代替' ='
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();
请查看getUrl的最后一个字母,它肯定会使用'%3D'。
但回归是一样的。
它投诉句子包括' ='分隔符。
[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&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= is not valid; the value of a query string parameter may not contain a '=' delimiter</Message>
-----------------------------直到这里添加--------------- -
我正在使用Amazon SNS API
我这样做的网址在浏览器上效果很好。
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
但是,如果我尝试使用Android。
这会返回400个错误请求。
<ErrorResponse xmlns="http://webservices.amazon.com/AWSFault/2005-15-09">
<Error>
<Type>Sender</Type>
<Code>MalformedQueryString</Code>
<Message>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%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>
我认为
查询字符串参数的值可能不包含&#39; =&#39;定界符
是问题的原因,但我无法弄清楚如何解决它。
相同的代码适用于iPhone。
它不仅仅适用于android。
我从这个函数
创建了URL字符串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;
}
答案 0 :(得分:1)
浏览器中的网址:签名= Dt9tXa0Rjl%2Ff6YxZ4JaPfsm%2BT%2BMX03gS712nIKKekAI%3D
Android中的网址:签名= Dt9tXa0Rjl%2Ff6YxZ4JaPfsm%2BT%2BMX03gS712nIWUekAI =