在android馅饼上我得到了对retrofit2请求的null响应。相同的代码正在所有以前的Android设备上工作。我已经在清单中添加了android:usesCleartextTraffic =“true”,它修复了http连接的问题,但我没有得到预期的响应在所有其他的帮助版本中,响应是预期的但不是馅饼。所以请提前帮助谢谢
Manifest.xml
<application
android:allowBackup="false"
tools:replace="android:allowBackup"
android:icon="@mipmap/cabad_logo_new"
android:label="@string/app_name"
android:networkSecurityConfig="@xml/network_security_config"
android:roundIcon="@mipmap/cabad_logo_new_round"
android:supportsRtl="true"
android:theme="@style/AppTheme"
android:usesCleartextTraffic="true">
主要信息
RetrofitInterface jsonPostService =
ServiceGenerator.createService(RetrofitInterface.class,
"http://xxx.xxx.xxx.xxx:8080/");
Call<LoginResult> call = jsonPostService.postRawJSON(jsonObject);
call.enqueue(new Callback<LoginResult>() {
@Override
public void onResponse(Call<LoginResult> call,
Response<LoginResult> response) {
try {
上面的代码在除了馅饼之外的所有Android设备中都运行正常馅饼得到空响应
转到应用程序标记中的Manifest.xml。添加这两行,如下所示。
android:usesCleartextTraffic="true"
tools:targetApi="m
<application
android:allowBackup="true"
android:hardwareAccelerated="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme"
android:usesCleartextTraffic="true"
tools:targetApi="m">
我希望它对你有用。