从发布的表单中获取名称值对(以解码格式)

时间:2011-04-07 10:24:20

标签: android http forms https httpwebrequest

我们正在为Android操作系统开发k9-email客户端的插件...我希望从已发布的表单中以解码的格式获取名称值对..

当我在gmail上点击“show original”后打开邮件时,会显示以下内容......如..

input name=3D"DefaultZDM" value=3D"https://voltage-pp-0000.july.co=
m/zdr" type=3D"hidden">
        input name=3D"ZFRDesignatedRecipient" value=3D"daphnebarretto@gmai=
l.com" type=3D"hidden">
        div style=3D"width: 1px; max-width: 1px; min-height: 1px; max-heig=
ht: 1px; overflow: hidden; padding: 5px;">
            pre style=3D"width: 1px; max-width: 1px; min-height: 1px; max-=
height: 1px; overflow: hidden; padding: 5px;">               =20
-----BEGIN VOLTAGE SECURE BLOCK V2-----
pt7tH1g22PVBtplPHn6zQgtRS2LFWbVavN5ZMOWs+S/x5OiPmWNy+Na8Xek9ICpE
3cm5xa5dIYvgYiYLbk8C0CuTd6koONPGs2IH2IQhm32phDpafXoa/1n3xOcfuuSB
v79H3sWZtW7EKy2hblpKi+0Y9KOZvpaL7nSd6tz9EVrA7XBa9nM1fvpBWvOsWIkA
VeYgMgjMFpLOVsastOqj3eJW7Jp+u4cm5n8PWAI4T9YuETtP/waOvYF8TAMI8Vey
3y09ZmJ2BS9VLhPKMJHSod6cYeSbD1gRwPoVp+AybnKz+BeBzd2DjBHS+sbd7/Va
Gn1beoCwfdPAteYxWcFShb6Sznw7whlZDyDnwtCwqrcHOpHIYkzXp4N5/4qzUzof
/QyBRY35rSciihyKqdo=3D
-----END VOLTAGE SECURE BLOCK V2-----

            </pre>
        </div>
    </font>
</td></tr>
</tbody></table>
    =20
</div>
</div>
从上面输入标签,我想得到的 DefaultZDM="https://voltage-pp-0000.july.com/zdr"ZFRDesignatedRecipient="daphnebarretto@gmail.com"

谢谢..

1 个答案:

答案 0 :(得分:1)

一个想法是使用正则表达式来查找匹配项。下面是一个如何使用正则表达式来打破160个字符的字符串的示例,但您可以使用以下命令轻松修改它:

Pattern p = Pattern.compile("DefaultZDM\" value=3D\"(.*)\"|ZFRDesignatedRecipient\" value=3D\"(.*)\""

我确定我没有正确的模式,但这是一个开始。这将匹配您想要的值对,您可以将它们分配给代码中的变量。

protected ArrayList<String> splitMsg(SmsMessage smsMessage) {
        ArrayList<String> smt;
        Pattern p = Pattern.compile(".{1,160}");
        Matcher regexMatcher = p.matcher(smsMessage.getMsgBody());
        smt = new ArrayList<String>();
        while (regexMatcher.find()) {
            smt.add(regexMatcher.group());
        }
        return smt;
    }