添加主机识别
This commit is contained in:
		| @@ -1,8 +1,8 @@ | ||||
| #Created by .winboll/winboll_app_build.gradle | ||||
| #Wed Jun 04 03:20:04 GMT 2025 | ||||
| #Wed Jun 04 04:10:28 GMT 2025 | ||||
| stageCount=5 | ||||
| libraryProject=libappbase | ||||
| baseVersion=15.8 | ||||
| publishVersion=15.8.4 | ||||
| buildCount=3 | ||||
| buildCount=7 | ||||
| baseBetaVersion=15.8.5 | ||||
|   | ||||
| @@ -9,7 +9,8 @@ | ||||
|         android:label="@string/app_name" | ||||
|         android:theme="@style/MyAPPBaseTheme" | ||||
|         android:resizeableActivity="true" | ||||
|         android:process=":App"> | ||||
|         android:process=":App" | ||||
|         android:networkSecurityConfig="@xml/network_security_config"> | ||||
|  | ||||
|         <activity | ||||
|             android:name=".MainActivity" | ||||
|   | ||||
							
								
								
									
										12
									
								
								appbase/src/main/res/xml/network_security_config.xml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								appbase/src/main/res/xml/network_security_config.xml
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,12 @@ | ||||
| <?xml version="1.0" encoding="utf-8"?> | ||||
| <network-security-config> | ||||
|     <!-- 允许访问 winboll.cc 及其子域名(原配置) --> | ||||
|     <domain-config cleartextTrafficPermitted="true"> | ||||
|         <domain includeSubdomains="true">winboll.cc</domain> | ||||
|     </domain-config> | ||||
|  | ||||
|     <!-- **新增:允许访问 IP 地址 10.8.0.250** --> | ||||
|     <domain-config cleartextTrafficPermitted="true"> | ||||
|         <domain includeSubdomains="false">10.8.0.250</domain> <!-- 不包含子域名 --> | ||||
|     </domain-config> | ||||
| </network-security-config> | ||||
| @@ -1,8 +1,8 @@ | ||||
| #Created by .winboll/winboll_app_build.gradle | ||||
| #Wed Jun 04 03:20:04 GMT 2025 | ||||
| #Wed Jun 04 04:10:28 GMT 2025 | ||||
| stageCount=5 | ||||
| libraryProject=libappbase | ||||
| baseVersion=15.8 | ||||
| publishVersion=15.8.4 | ||||
| buildCount=3 | ||||
| buildCount=7 | ||||
| baseBetaVersion=15.8.5 | ||||
|   | ||||
| @@ -3,9 +3,11 @@ package cc.winboll.studio.libappbase.activities; | ||||
| import android.app.Activity; | ||||
| import android.os.Bundle; | ||||
| import android.view.View; | ||||
| import cc.winboll.studio.libappbase.BuildConfig; | ||||
| import cc.winboll.studio.libappbase.LogUtils; | ||||
| import cc.winboll.studio.libappbase.R; | ||||
| import cc.winboll.studio.libappbase.winboll.IWinBoLLActivity; | ||||
| import java.io.IOException; | ||||
| import okhttp3.OkHttpClient; | ||||
| import okhttp3.Request; | ||||
| import okhttp3.Response; | ||||
| @@ -19,6 +21,8 @@ public class YunActivity extends Activity implements IWinBoLLActivity { | ||||
|  | ||||
|     public static final String TAG = "YunActivity"; | ||||
|  | ||||
|     String mYunHost = ""; | ||||
|  | ||||
|     @Override | ||||
|     public Activity getActivity() { | ||||
|         return this; | ||||
| @@ -33,7 +37,7 @@ public class YunActivity extends Activity implements IWinBoLLActivity { | ||||
|     protected void onCreate(Bundle savedInstanceState) { | ||||
|         super.onCreate(savedInstanceState); | ||||
|         setContentView(R.layout.activity_yun); | ||||
|  | ||||
|         mYunHost = BuildConfig.DEBUG ?"http://10.8.0.250:456": "https://yun.winboll.cc"; | ||||
|     } | ||||
|  | ||||
|     public void onTestYun(View view) { | ||||
| @@ -49,20 +53,39 @@ public class YunActivity extends Activity implements IWinBoLLActivity { | ||||
|     void testYun() { | ||||
|         OkHttpClient client = new OkHttpClient(); | ||||
|         Request request = new Request.Builder() | ||||
|             .url("https://yun.winboll.cc/backups/") | ||||
|             .url(mYunHost + "/backups/") | ||||
|             .build(); | ||||
|  | ||||
|         Response response = null; | ||||
|         try { | ||||
|             Response response = client.newCall(request).execute(); | ||||
|             if (response.isSuccessful()) { // 状态码 200-399 均视为成功 | ||||
|                 //System.out.println("OK"); | ||||
|                 LogUtils.d(TAG, "OK"); | ||||
|             response = client.newCall(request).execute(); | ||||
|             if (response.isSuccessful()) { | ||||
|                 String responseBody = ""; | ||||
|                 if (response.body() != null) { | ||||
|                     responseBody = response.body().string(); | ||||
|                 } | ||||
|  | ||||
|                 // 正则匹配:任意主机名 -> Test OK(主机名部分匹配非空字符) | ||||
|                 boolean isMatch = responseBody.matches(".+? -> Test OK"); | ||||
|  | ||||
|                 if (isMatch) { | ||||
|                     LogUtils.d(TAG, responseBody); | ||||
|                 } else { | ||||
|                     LogUtils.d(TAG, "响应内容不匹配,内容:" + responseBody); | ||||
|                 } | ||||
|             } else { | ||||
|                 //System.out.println("请求失败,状态码:" + response.code()); | ||||
|                 LogUtils.d(TAG, "请求失败,状态码:" + response.code()); | ||||
|             } | ||||
|         } catch (IOException e) { | ||||
|             LogUtils.d(TAG, "读取响应体失败:" + e.getMessage()); | ||||
|         } catch (Exception e) { | ||||
|             LogUtils.d(TAG, e, Thread.currentThread().getStackTrace()); | ||||
|             LogUtils.d(TAG, "异常:" + e.getMessage()); | ||||
|             e.printStackTrace(); // Java 7 需显式打印堆栈 | ||||
|         } finally { | ||||
|             // 手动关闭 Response(Java 7 不支持 try-with-resources) | ||||
|             if (response != null && response.body() != null) { | ||||
|                 response.body().close(); | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|  | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 ZhanGSKen
					ZhanGSKen