WSSE时间戳一代的Andr​​oid

WSSE时间戳一代的Andr​​oid

本文介绍了WSSE时间戳一代的Andr​​oid的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有WSSE身份验证的Web服务。 Web服务是写在Symfony2中,我可以访问它throught一个PHP客户端和也与插件铬称为REST控制台,所以它的工作原理。手动生成的头我用。

I have a web service with WSSE authentication. The web service is written in Symfony2 and I can access it throught a PHP client and also with the plugin for chrome called REST Console, so it works. To generate the headers manually I have used this wsse generator.

为了使Android客户端我按照这个的,它的工作原理,但只有当它不产生时间戳。

To make the Android client I have followed this tutorial, it works but only when it doesn't generate the timestamp.

在code这产生戳记是:

The code which generate the timestamp is:

private static final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
...
private String generateTimestamp() {
    sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
    return sdf.format(new Date());
}

它返回它是正确的字符串,其格式和一切看起来完美,但它告诉未授权,但是当我直接写的时间戳这样它的工作原理:

The String it returns it is correct, the format and everything look perfect but it tells "not authorized", but it works when I write the timestamp directly like this:

private String generateTimestamp() {
    return "2014-03-25T09:00:26Z";
}

我已经检查了编码,试图EN code像UTF-8和CP-1252(文件编码):

I have checked the encoding, trying to encode it like UTF-8 And Cp-1252 (the file encoding):

private String generateTimestamp() {
    sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
    String hora = sdf.format(new Date());

    String correctString = "fail";
    try {
        correctString = new String(hora.getBytes(), "UTF-8");
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
    correctString.hashCode();
    //String buena = "2014-03-25T08:10:59Z";
    return correctString ;
}

我生成使用Calendar.YEAR +的Calendar.MONTH时间戳....但仍然无法正常工作。

I generated the timestamp using Calendar.YEAR + Calendar.MONTH.... but still doesn't work.

目前,我想测试它在真正的手机,但我不认为这是一个模拟器的问题。

At the moment I am trying to test it in a real phone but I don't think it is an emulator problem.

你有什么建议吗?非常感谢你提前!

Do you have any suggestion? Thank you very much in advance!

推荐答案

这是工作的解决方案是:

The solution that works is:

private String generateTimestamp() {
    sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
    String hora = sdf.format(new Date());

    return "\""+hora+"\"";
}

问题是,最终的字符串的Andr​​oid发送到Web服务有两个双引号是这样的:

The problem is that the final String that Android sends to the webservice has two double quotes like this:

X-WSSE: UsernameToken Username="esther", PasswordDigest="FgWu9GAKkbmsc52fZHu3VINHlKw=", Nonce="OWVkNDMxMWY2OGE4MTZjOQ==", Created=""2014-03-25T09:00:26Z""

但它的工作原理,即使不是最好的解决方案。

But it works, even if it is not the best solution.

我认为它是Java的中间/ Android版/ SimpleDateFormat的是如何生成的字符串是不同的,但是......

I think it is a different between how Java/Android/SimpleDateFormat generate the string, but...

我已经测试试图串联空字符串,但它仍然无法正常工作。

I have tested trying to concatenate empty string but it still doesn't work.

这篇关于WSSE时间戳一代的Andr​​oid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-31 10:19