异步任务和https android

时间:2013-08-19 23:18:02

标签: android ssl android-asynctask

我有一个Android应用程序,并在我的网站上添加了ssl以确保登录时的登录信息。我有一个异步任务,它发送信息以检查数据库等。

设置我的ssl correctley后,看到它在我的网站上有效。我尝试将http:更改为https:在我的异步任务的网址中,它因此错误而崩溃:

08-19 19:14:16.779    9314-9465/com.beerportfolio.beerportfoliopro E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #1
        java.lang.RuntimeException: An error occured while executing doInBackground()
        at android.os.AsyncTask$3.done(AsyncTask.java:299)
        at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
        at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
        at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
        at java.util.concurrent.FutureTask.run(FutureTask.java:137)
        at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
        at java.lang.Thread.run(Thread.java:864)
        Caused by: java.lang.IllegalArgumentException: Illegal character in query at index 50: https://myDBUrl
        at java.net.URI.create(URI.java:727)
        at org.apache.http.client.methods.HttpGet.<init>(HttpGet.java:75)
        at com.example.beerportfoliopro.ReadLogInJSON.readJSONFeed(ReadLogInJSON.java:90)
        at com.example.beerportfoliopro.ReadLogInJSON.doInBackground(ReadLogInJSON.java:37)
        at com.example.beerportfoliopro.ReadLogInJSON.doInBackground(ReadLogInJSON.java:24)
        at android.os.AsyncTask$2.call(AsyncTask.java:287)
        at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
        ... 5 more

更新

FOund out错误不在ssl部分,但是当使用自动更正键盘在用户名末尾添加空格时,它会崩溃。如果输入,我该如何消除这个空间?

1 个答案:

答案 0 :(得分:-1)

您可以随时编写一个util函数并使用它来避免此类错误:

private String urlEncode(String url)
    {
        if(url == null)
            return null;
        url = url.replace("[","");
        url = url.replace("]","");
        url = url.replaceAll(" ","%20");
        return url;
    }