0

request メソッドを使用HttpURLConnectionすると、 「 https://www.myexample.com/login?u=test&p=test123GET 」で REST API に接続できますが、「 http://dev.myexample.com/login?u=test&pでは接続できません」=test123 ".

同じデバイスのデフォルトの Android ブラウザで「壊れた」URL を確認できます。期待どおりのXML応答が得られるためECONNREFUSED、アプリ内で受信している理由がわかりません。この問題を自分で解決したいのですが、何が問題なのかさえわかりません。何か案は?

04-05 18:41:15.890 2158-13245/myexample.android.phone.MyApp W/System.err: java.net.ConnectException: failed to connect to dev.lakewoodchurch.com/92.242.xx.xx (port 443): connect failed: ECONNREFUSED (Connection refused)
04-05 18:41:15.890 2158-13245/myexample.android.phone.MyApp W/System.err:     at libcore.io.IoBridge.connect(IoBridge.java:124)
04-05 18:41:15.890 2158-13245/myexample.android.phone.MyApp W/System.err:     at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:183)
04-05 18:41:15.890 2158-13245/myexample.android.phone.MyApp W/System.err:     at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:456)
04-05 18:41:15.890 2158-13245/myexample.android.phone.MyApp W/System.err:     at java.net.Socket.connect(Socket.java:882)
04-05 18:41:15.890 2158-13245/myexample.android.phone.MyApp W/System.err:     at com.android.okhttp.internal.Platform.connectSocket(Platform.java:139)
04-05 18:41:15.890 2158-13245/myexample.android.phone.MyApp W/System.err:     at com.android.okhttp.Connection.connect(Connection.java:148)
04-05 18:41:15.890 2158-13245/myexample.android.phone.MyApp W/System.err:     at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:276)
04-05 18:41:15.890 2158-13245/myexample.android.phone.MyApp W/System.err:     at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:211)
04-05 18:41:15.890 2158-13245/myexample.android.phone.MyApp W/System.err:     at com.android.okhttp.internal.http.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:373)
04-05 18:41:15.890 2158-13245/myexample.android.phone.MyApp W/System.err:     at com.android.okhttp.internal.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:106)
04-05 18:41:15.890 2158-13245/myexample.android.phone.MyApp W/System.err:     at com.android.okhttp.internal.http.DelegatingHttpsURLConnection.connect(DelegatingHttpsURLConnection.java:89)
04-05 18:41:15.890 2158-13245/myexample.android.phone.MyApp W/System.err:     at com.android.okhttp.internal.http.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl.java:25)
04-05 18:41:15.890 2158-13245/myexample.android.phone.MyApp W/System.err:     at myexample.android.phone.MyApp.XMLParser.getXMLFromURLGet(XMLParser.java:185)
04-05 18:41:15.890 2158-13245/myexample.android.phone.MyApp W/System.err:     at myexample.android.phone.MyApp.Login$1$1.run(Login.java:133)
04-05 18:41:15.890 2158-13245/myexample.android.phone.MyApp W/System.err:     at myexample.android.phone.MyApp.GenericAsyncTask.doInBackground(GenericAsyncTask.java:15)
04-05 18:41:15.890 2158-13245/myexample.android.phone.MyApp W/System.err:     at myexample.android.phone.MyApp.GenericAsyncTask.doInBackground(GenericAsyncTask.java:5)
04-05 18:41:15.890 2158-13245/myexample.android.phone.MyApp W/System.err:     at android.os.AsyncTask$2.call(AsyncTask.java:288)
04-05 18:41:15.890 2158-13245/myexample.android.phone.MyApp W/System.err:     at java.util.concurrent.FutureTask.run(FutureTask.java:237)
04-05 18:41:15.890 2158-13245/myexample.android.phone.MyApp W/System.err:     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
04-05 18:41:15.890 2158-13245/myexample.android.phone.MyApp W/System.err:     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
04-05 18:41:15.890 2158-13245/myexample.android.phone.MyApp W/System.err:     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
04-05 18:41:15.890 2158-13245/myexample.android.phone.MyApp W/System.err:     at java.lang.Thread.run(Thread.java:818)
04-05 18:41:15.890 2158-13245/myexample.android.phone.MyApp W/System.err: Caused by: android.system.ErrnoException: connect failed: ECONNREFUSED (Connection refused)
04-05 18:41:15.890 2158-13245/myexample.android.phone.MyApp W/System.err:     at libcore.io.Posix.connect(Native Method)
04-05 18:41:15.890 2158-13245/myexample.android.phone.MyApp W/System.err:     at libcore.io.BlockGuardOs.connect(BlockGuardOs.java:111)
04-05 18:41:15.890 2158-13245/myexample.android.phone.MyApp W/System.err:     at libcore.io.IoBridge.connectErrno(IoBridge.java:137)
04-05 18:41:15.890 2158-13245/myexample.android.phone.MyApp W/System.err:     at libcore.io.IoBridge.connect(IoBridge.java:122)
04-05 18:41:15.890 2158-13245/myexample.android.phone.MyApp W/System.err:   ... 21 more
04-05 18:41:15.890 2158-13245/myexample.android.phone.MyApp W/System.err: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String java.lang.StringBuilder.toString()' on a null object reference
04-05 18:41:15.890 2158-13245/myexample.android.phone.MyApp W/System.err:     at myexample.android.phone.MyApp.XMLParser.getXMLFromURLGet(XMLParser.java:228)
04-05 18:41:15.890 2158-13245/myexample.android.phone.MyApp W/System.err:     at myexample.android.phone.MyApp.Login$1$1.run(Login.java:133)
04-05 18:41:15.890 2158-13245/myexample.android.phone.MyApp W/System.err:     at myexample.android.phone.MyApp.GenericAsyncTask.doInBackground(GenericAsyncTask.java:15)
04-05 18:41:15.890 2158-13245/myexample.android.phone.MyApp W/System.err:     at myexample.android.phone.MyApp.GenericAsyncTask.doInBackground(GenericAsyncTask.java:5)
04-05 18:41:15.890 2158-13245/myexample.android.phone.MyApp W/System.err:     at android.os.AsyncTask$2.call(AsyncTask.java:288)
04-05 18:41:15.890 2158-13245/myexample.android.phone.MyApp W/System.err:     at java.util.concurrent.FutureTask.run(FutureTask.java:237)
04-05 18:41:15.890 2158-13245/myexample.android.phone.MyApp W/System.err:     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
04-05 18:41:15.890 2158-13245/myexample.android.phone.MyApp W/System.err:     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
04-05 18:41:15.890 2158-13245/myexample.android.phone.MyApp W/System.err:     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
04-05 18:41:15.890 2158-13245/myexample.android.phone.MyApp W/System.err:     at java.lang.Thread.run(Thread.java:818)

これを見たい場合:

public static String getXMLFromURLGet(String url, HashMap<String,String> params) {
    URI uri = XMLParser.encodeUrl(url);

    String xml = null;
    URL link;
    BufferedReader reader = null;
    StringBuilder stringBuilder=null;

    try {
        // convert params to string
        if(params != null && params.size() > 0) {
            String op = "?";
            for(HashMap.Entry<String,String> entry : params.entrySet()) {
                url += op + entry.getKey() + "=" + URLEncoder.encode(entry.getValue(), "UTF-8");
                op = "&";
            }
        }

        Log.i("XMLParser", "Get URL: " + url);
        link = new URL(url);
        HttpURLConnection connection = (HttpURLConnection) link.openConnection();
        connection.setRequestMethod("GET");

        XMLParser.loadCookiesToConnection(connection);
        connection.connect();

        if(LCHApplication.DEBUG) {
            System.out.println("response code: " + connection.getResponseCode());
            Map<String, List<String>> map = connection.getHeaderFields();
            System.out.println("Printing Response Header...\n");
            for (Map.Entry<String, List<String>> entry : map.entrySet()) {
                System.out.println("Key : " + entry.getKey()
                        + " ,Value : " + entry.getValue());
            }
        }

        XMLParser.storeCookiesFromConnection(connection);

        InputStream is = connection.getInputStream();
        InputStreamReader ir = new InputStreamReader(is);
        reader = new BufferedReader(ir);
        stringBuilder = new StringBuilder();

        String line = null;
        while ((line = reader.readLine()) != null)
        {
            stringBuilder.append(line + "\r");
        }
    } catch (Exception e) {
        e.printStackTrace();
        Crashlytics.logException(e);
    } finally {
        if (reader != null)
        {
            try
            {
                reader.close();
            }
            catch (IOException ioe)
            {
                ioe.printStackTrace();
                Crashlytics.logException(ioe);
            }
        }
    }

    try {
        xml = stringBuilder.toString();
    } catch (Exception e) {
        e.printStackTrace();
        Crashlytics.logException(e);

        try {
            LCHApplication.instance.dialogServerError(MainContainer.instance.getContext());
        } catch(Exception e1) {}
    }
    return xml;

}
4

1 に答える 1

0

HttpUrlConnection接続を行っているものです。443ポートが使用されていることに気付きました。http://アドレスを指定したため、これは問題です。

http6.0 Android アップデートでは、すべてのリクエストをに変更するオーバーライドがありましたhttps。何かが起きていることを障害ラインから知る必要がありました。

うまくいけば、誰かが私の見落としから利益を得ることができます.

于 2016-04-07T13:54:30.357 に答える