1


I have a problem in android,
this project get some before,
but now the webapi turns http to https and it can't works,
I have no idea how to fix it,

private AQuery aq;
aq = new AQuery(this);
    aq.ajax(url, String.class, new AjaxCallback<String>() {
                        public void callback(String url, String string,
                                             AjaxStatus status) {
                            if (status.getCode() == 200 && !string.equals("")
                                    && result.indexOf(Constants.STATUS) != -1) {
                                StatusMsg statusMsg = JSONParserHelper
                                        .statusMsgParser(result);
                                if (statusMsg != null) {
                                    String showMsg = JSONParserHelper.getStatusMsg(
                                            Register.this, statusMsg);
                                    Message msg = mHandler
                                            .obtainMessage(1, showMsg);
                                    mHandler.sendMessage(msg);
                                } else {
                                    Message m = mHandler.obtainMessage(2,
                                            getString(R.string.link_failure));
                                    mHandler.sendMessage(m);
                                }
                            } else {
                                Message m = mHandler.obtainMessage(2,
                                        getString(R.string.link_failure));
                                mHandler.sendMessage(m);
                            }
                        }

                        ;
                    });

does anyone can tell me how to get https?
or I have to use SSLSocket to fix it?

Louis
  • 123
  • 1
  • 3
  • 11
  • Tons of things can go wrong with SSL. Could you post the stack trace this code is producing? – jjm Jan 07 '15 at 02:27
  • 1
    the question is status . getCode () = -101,and string is null – Louis Jan 07 '15 at 03:09
  • It's very odd that it's returning `-101` since all http status codes are *positive*, but a status of `101` indicates that the server wants to upgrade to HTTPS. I took a quick look at the the AQuery code and it uses HttpUrlConnection, which *should* handle the upgrade automatically. This is probably a dumb question, but does the url you're passing to aq.ajax start with https://? If that's not the issue it might be something on the server side. Can you access the url with a browser? If all else fails, it might be a bug in aq; you could use any of a number of nice android http libs. – jjm Jan 07 '15 at 03:25
  • this url works on browser,so I have to use other libs or code a function to solve it?Is there any sample code for SSL? – Louis Jan 07 '15 at 04:02
  • You certainly don't have to work with SSL directly. I would just try a different library. https://github.com/kevinsawicki/http-request is very simple, you can just drop the single java file into your project and you're good to go. There's also http://square.github.io/okhttp/, which is also very simple, although you'll have to add a jar to your project. Finally, you can try the org.apache.http libraries that come with Android (DefaultHttpClient and friends), which require a few more lines of code to use but give you more flexibility. In all of these cases you'll have to use an AsyncTask. – jjm Jan 07 '15 at 18:53

2 Answers2

1

I was facing the same issue with one of my app. It turns out that I was missing the required permission for Internet which is required in aquery.

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

Please see if these permissions are present in you androidmanifest.xml. Hope this helps

Sahil Kapoor
  • 604
  • 4
  • 9
0

I know its too late, but if someone have same problem (status -101)try this add line in your application tag of your manifest.xml

<uses-library android:name="org.apache.http.legacy" android:required="false"/>