-
Notifications
You must be signed in to change notification settings - Fork 25
Open
Description
问题1:就算queries没有一个,也不能为null
就算queries没有一个,也不能为null。为null会导致计算出来的Authorization不正确。我觉得这里可以加固一下,要么非空,要么内部判断一下如果为空也不让计算出错。
测试代码如下:
public String BASE_URL = "";
public String URL_PATH = "/2016-08-15/proxy/guide-hello_world/test_fc_token/";
private static final String AccessKeyID = "";
private static final String AccessKeySecret = "";
private String getGmtTime() {
final Date currentTime = new Date();
final SimpleDateFormat GMT_FOMART = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss z");
GMT_FOMART.setTimeZone(TimeZone.getTimeZone("GMT"));
String date = GMT_FOMART.format(currentTime);
System.out.println("GMT time: " + date);
return date;
}
private void test() throws Exception {
Map<String, String> headers = new HashMap();
Map<String, String> queries = new HashMap();
String date = getGmtTime();
headers.put("Date", date);
//TODO: queries can not be null
String composed = FcSignatureComposer.composeStringToSign(GET, URL_PATH, headers, queries);
String sign = FcSignatureComposer.signString(composed, AccessKeySecret);
String Authorization = "FC " + AccessKeyID + ":" + sign;
System.out.println("Authorization: " + Authorization);
URL url = new URL(BASE_URL + URL_PATH);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestProperty("Date", date);
conn.setRequestProperty("Authorization", Authorization);
conn.setConnectTimeout(3000);
conn.setReadTimeout(3000);
conn.setRequestMethod("GET");
conn.connect();
InputStream is = conn.getInputStream();
String s = readStringFromIs(is, "UTF-8");
System.out.println(s);
}问题2:时间格式写到sdk中
另外一个问题,函数计算后台要求的时间格式并非标准GMT模式,无法从系统中直接获取格式化好的时间格式。我觉得可以将Format格式写到sdk中,这样大家直接使用就好了,不用一点一点的测试这个时间格式。我已经把我的测试出来的合法时间格式帖出来了,你们可以集成到sdk中。
问题3:认证方法结合网络框架
另外这个认证实质是对header path和query进行了一些运算,并写回到了header中;这个操作建议能和比较强大的网络访问框架结合起来,比如Retrofit2。
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels