1

i'am using the HttpsURLConnection to get some information via GET Method. I have working code in Java that uses basic authentification and a Trustmanager like this (HTTPS GET (SSL) with Android and self-signed server certificate)

private String sendHTTPrequest(String uri, HttpRequestMethods method,
        String user, String password, int timeout, String body)
        throws Exception {
    if (sxtm != null) {
        URL url = new URL(uri);
        HttpsURLConnection httpsRequest = (HttpsURLConnection) url
                .openConnection();
        httpsRequest.setSSLSocketFactory(sxtm.getSSLInstance()
                .getSocketFactory());
        httpsRequest.setHostnameVerifier(sxtm.getHostInstance());
        httpsRequest.setRequestMethod(""+method);
        httpsRequest.setConnectTimeout(timeout);
        httpsRequest.setDoInput(true);
        httpsRequest.setDoOutput(true);
        if (useDigist) {
            // Currently not in use
            setDigestAuthentication(httpsRequest, user, password);
        } else {
            String authString = user + ":" + password;
            byte[] authEncBytes = Base64Coder.encode(authString
                    .getBytes());
            String authStringEnc = new String(authEncBytes);
            httpsRequest.addRequestProperty("Authorization", "Basic "
                    + authStringEnc);
        }

        System.out.println(httpsRequest.getResponseCode());

        if (httpsRequest.getContentType() != null
                && httpsRequest.getContentType().contains("xml")) {
            DocumentBuilderFactory dfactory = DocumentBuilderFactory
                    .newInstance();
            DocumentBuilder builder = dfactory.newDocumentBuilder();
            lastXmlContent = builder.parse(httpsRequest.getInputStream());
            return httpsRequest.getResponseMessage();
        } else {
            return "No XML found";
        }
    }
    return "TrustManager is null";
}

The Base64Coder is an own class to switch between normal Java JRE and Android (This works, on both Runtimes the same result)

Now my Problem is on Java JRE everything works fine, but on Android i always get a 405 code back!??!?!?

In the Android App the Internet Permission is set and the Server is available using Firefox

Community
  • 1
  • 1
zrb
  • 53
  • 7
  • *Self learning on* http://stackoverflow.com/questions/8187188/android-4-0-ics-turning-httpurlconnection-get-requests-into-post-requests/8538539#8538539 Awesome behaviour of Android Problem fixed – zrb Aug 08 '14 at 09:08

0 Answers0