0

I have built a sub-directory type multisite and installed wp rest api on my localhost. Next step would be to connect the multisite to my android app using the rest api. This is where things go wrong. I have replaced the address from a)localhost/mil/wp-json/... to b)10.0.2.2:80/mil/wp-json/... The result : ECONNREFUSED(Connection Refused) . Here is the complete trace:

D/TRENDTASK: doInBackground do: http://10.0.2.2:80/mil/socialnetwork/wp-json/wp/v2/posts?page=1
W/System.err: java.net.ConnectException: Failed to connect to localhost/127.0.0.1:80
        at okhttp3.internal.connection.RealConnection.connectSocket(RealConnection.java:248)
        at okhttp3.internal.connection.RealConnection.connect(RealConnection.java:166)
        at okhttp3.internal.connection.StreamAllocation.findConnection(StreamAllocation.java:257)
        at okhttp3.internal.connection.StreamAllocation.findHealthyConnection(StreamAllocation.java:135)
W/System.err:     at okhttp3.internal.connection.StreamAllocation.newStream(StreamAllocation.java:114)
        at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:42)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
        at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:93)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
        at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
        at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:126)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
        at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:254)
W/System.err:     at okhttp3.RealCall.execute(RealCall.java:92)
        at com.reapsanalytics.movingisliving.PostcardFragment$trendTask.doInBackground(PostcardFragment.java:393)
        at com.reapsanalytics.movingisliving.PostcardFragment$trendTask.doInBackground(PostcardFragment.java:378)
        at android.os.AsyncTask$2.call(AsyncTask.java:333)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
        at java.lang.Thread.run(Thread.java:764)
    Caused by: java.net.ConnectException: failed to connect to localhost/127.0.0.1 (port 80) from /127.0.0.1 (port 42673) after 10000ms: isConnected failed: ECONNREFUSED (Connection refused)
        at libcore.io.IoBridge.isConnected(IoBridge.java:273)
        at libcore.io.IoBridge.connectErrno(IoBridge.java:188)
        at libcore.io.IoBridge.connect(IoBridge.java:130)
W/System.err:     at java.net.PlainSocketImpl.socketConnect(PlainSocketImpl.java:129)
        at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:356)
        at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
        at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
        at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:357)
        at java.net.Socket.connect(Socket.java:616)
        at okhttp3.internal.platform.AndroidPlatform.connectSocket(AndroidPlatform.java:73)
        at okhttp3.internal.connection.RealConnection.connectSocket(RealConnection.java:246)
        ... 25 more
    Caused by: android.system.ErrnoException: isConnected failed: ECONNREFUSED (Connection refused)
        at libcore.io.IoBridge.isConnected(IoBridge.java:262)
W/System.err:   ... 35 more
W/System.err: java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.String.length()' on a null object reference
        at org.json.JSONTokener.nextCleanInternal(JSONTokener.java:116)
W/System.err:     at org.json.JSONTokener.nextValue(JSONTokener.java:94)
        at org.json.JSONArray.<init>(JSONArray.java:92)
        at org.json.JSONArray.<init>(JSONArray.java:108)
        at com.reapsanalytics.movingisliving.PostcardFragment.TrendParser(PostcardFragment.java:477)
W/System.err:     at com.reapsanalytics.movingisliving.PostcardFragment.getRetrofitTrend(PostcardFragment.java:309)
        at com.reapsanalytics.movingisliving.PostcardFragment$2.onTabSelected(PostcardFragment.java:182)
        at com.google.android.material.tabs.TabLayout.dispatchTabSelected(TabLayout.java:1730)
        at com.google.android.material.tabs.TabLayout.selectTab(TabLayout.java:1723)
        at com.google.android.material.tabs.TabLayout.selectTab(TabLayout.java:1691)
        at com.google.android.material.tabs.TabLayout$Tab.select(TabLayout.java:2028)
        at com.google.android.material.tabs.TabLayout$TabView.performClick(TabLayout.java:2213)
W/System.err:     at android.view.View$PerformClick.run(View.java:24770)
        at android.os.Handler.handleCallback(Handler.java:790)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:164)
W/System.err:     at android.app.ActivityThread.main(ActivityThread.java:6494)
W/System.err:     at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)

Now it works fine when using postman with address a. Prior to this, I had tried integrating a normal wordpress single site with android and everything worked fine. So I ran some more tests using postman as well as firefox. 1a)localhost/mil/wp-json - returns json. 1b)localhost/mil/site1/wp-json - works as well. 2)127.0.0.1/mil/wp-json - redirects/loads the home page. 3)192.168.0.7/mil/wp-json - redirects/loads the home page. Yet, the same when used with a single site installation works perfectly fine. The multi-site has 3 sub-sites, with three different theme. They all face the same problems as the main-site. I am somewhat of a beginner at WordPress, so Am I missing something here ? The multi-site is not accepting the ip address in the address bar in place of localhost.

Just in case here's the wp-config code specific to my multisite:

/* Multisite */
define('WP_ALLOW_MULTISITE', true);
define('MULTISITE', true);
define('SUBDOMAIN_INSTALL', false);
define('DOMAIN_CURRENT_SITE', 'localhost');
define('PATH_CURRENT_SITE', '/mil/');
define('SITE_ID_CURRENT_SITE', 1);
define('BLOG_ID_CURRENT_SITE', 1); 
  • I tried network deactivating all plugins except for WP_REST_API, but no change. – Big Bong Apr 9 at 10:14
0

In your wp-config.php replace localhost with 127.0.0.1. Also, make some updates in your database. Update options tables for each site and replace localhost with 127.0.0.1 and same in wp_blogs table.

  • I made the changes as you suggested, only thing to happen is localhost being replaced by 127.0.0.1. All the above mentioned problems still persist, like the ECONNREFUSED in Android, and the home page redirection when I use my local IP address. – Big Bong Apr 9 at 9:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.