【发布时间】:2020-01-06 17:59:04
【问题描述】:
在 android pie 上,retrofit2 请求的响应为空。相同的代码适用于所有以前的 android 设备。我在清单中添加了 android:usesCleartextTraffic="true" ,它修复了 http 连接的问题,但在所有其他 androided 版本中我没有得到预期的响应,但不是在饼图中。所以请帮忙提前谢谢
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 {
以上代码在除 pie 之外的所有 android 设备上都可以正常工作。馅饼得到空响应
【问题讨论】:
-
@Intsab Haider 我已经在使用该解决方案,但它无法正常工作,因为它允许 http 流量,但没有得到预期的响应。
-
你能分享一下 JSON 在 Pie 之前和之后的区别吗?
-
只有我得到的响应在饼图中为空。 pie 和以前的 android 版本的所有代码都是相同的
标签: android null response android-9.0-pie