我已经构建了一个子目录类型的multisite,并在本地主机上安装了wp rest api。下一步是使用rest api将多站点连接到我的android应用程序。这就是问题所在。我已将地址替换为a)localhost/mil/wp-json/...
至b)10.0.2.2:80/mil/wp-json/...
结果:ECONNREFUSED(Connection Refused)
. 以下是完整的跟踪:
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)
现在,当使用地址为a的postman时,它工作得很好。在此之前,我曾尝试将一个普通的wordpress单一站点与android集成,一切都很好。所以我使用postman和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
.然而,当与单个站点安装一起使用时,同样的方法可以非常好地工作。这个多站点有三个子站点,有三个不同的主题。它们都面临着与主站点相同的问题。我是WordPress的初学者,所以我在这里遗漏了什么吗?多站点不接受地址栏中的ip地址而不是本地主机。
以防万一,以下是特定于我的多站点的wp配置代码:
/* 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);