小编Cli*_*int的帖子

Catching an exception that is nested into another exception

I want to catch an exception, that is nested into another exception. I'm doing it currently this way:

} catch (RemoteAccessException e) {
    if (e != null && e.getCause() != null && e.getCause().getCause() != null) {
        MyException etrp = (MyException) e.getCause().getCause();
        ...
    } else {
        throw new IllegalStateException("Error at calling service 'service'");
    }
}
Run Code Online (Sandbox Code Playgroud)

Is there a way to do this more efficient and elegant?

java exception try-catch nested-exceptions

26
推荐指数
4
解决办法
4万
查看次数

URI查询中的布尔值?

在URI的查询部分中指定布尔值的首选方法是什么?普通的查询字符串看起来像

a=foo&b=bar
Run Code Online (Sandbox Code Playgroud)

假设我有一个带有布尔值的参数"c",我应该说明

a=foo&b=bar&c=1
Run Code Online (Sandbox Code Playgroud)

要么

a=foo&b=bar&c=True
Run Code Online (Sandbox Code Playgroud)

要么

a=foo&b=bar&c=true
Run Code Online (Sandbox Code Playgroud)

我检查了RFC 2396的查询组件部分,但没有指定如何表示布尔参数.所以我想知道的是通常(或合理)的方式是什么?

url uri http

26
推荐指数
3
解决办法
2万
查看次数

将Cookie存储在sharedpreferences中

我一直在试着弄清楚我的头发:我正在制作一个HttpsURLConnection并使用java.net.cookiemanager来管理我的cookie(根据我的理解,没有办法使用android.webkit.cookiemanager来HttpUrlConnection/HttpsUrlConnection? ).我需要将我的长时间cookie保存到以后的连接中.

遗憾的是,我无法使用http://loopj.com/android-async-http/并且它是PersistentCookieStore,因为我需要允许不受信任的证书(使用http://abhinavasblog.blogspot.se/2011/07/allow-untrusted -certificate-for-https.html).我已经尝试过单独使用他们的PersistentCookieStore但是他们正在使用apache cookie而我正在使用java.net cookies ...

这就是我尝试过的:

cManager = new CookieManager(null, CookiePolicy.ACCEPT_ALL);

private void setSharedPreferences(){
    List<HttpCookie> cookies = cManager.getCookieStore().getCookies();

    if (cookies.isEmpty()) {
        Log.d(tag,"no cookies received");
    } else {
        for (int i = 0; i < cookies.size(); i++) {
            if(cookies.get(i).getName().equals("rememberMe")) {
                editor.putString(
                        "rememberMe", cookies.get(i).toString());
                editor.commit();
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

当我在下次应用启动时检索cookie时:

SharedPreferences sharedPreferences = context.getSharedPreferences("PREF_NAME", Context.MODE_PRIVATE);
editor = sharedPreferences.edit();
String rememberString = sharedPreferences.getString("rememberMe", "none");

if (!rememberString.equals("none")) {
    Log.d("rememberME är inte", "none!");
    URI uriToCookie = null;
    try { …
Run Code Online (Sandbox Code Playgroud)

cookies android sharedpreferences httpsurlconnection

6
推荐指数
1
解决办法
5226
查看次数