android - Erreur 改造 获取
问题描述
我无法使用 Retrofit 库从我的 Wordpress API 中恢复数据。错误是:HTTP FAILED: java.net.UnknownHostException: Unable to resolve host "app.divion.fr": No address associated with hostname
接口客户端:
import androidx.appcompat.app.AppCompatActivity;
import retrofit2.Call;
import kotlin.contracts.Returns;
import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
public class ApiClient extends AppCompatActivity {
//Adresse de l'Api
public static final String BASE_URL = "https://app.divion.fr/wp-json/api/";
//Retrofit Api Client
private static Retrofit retrofit = null;
public static Retrofit getApiClient(){
HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
loggingInterceptor.level(HttpLoggingInterceptor.Level.BODY);
OkHttpClient client = new OkHttpClient.Builder()
.addInterceptor(loggingInterceptor)
.build();
if (retrofit == null){
retrofit = new Retrofit.Builder()
.baseUrl(BASE_URL)
.client(client)
.addConverterFactory(GsonConverterFactory.create())
.build();
}
return retrofit;
}
}
接口接口:
package com.example.allomairie.rest;
import java.util.Map;
import retrofit2.Call;
import retrofit2.http.GET;
import retrofit2.http.QueryMap;
公共接口 ApiInterface {
// Retrofit Interface
//JSON --> GSON Library --> Java Object
@GET("homepage_api")
Call<Object> getHomepageApi(@QueryMap Map<String, String> params);
}
清单.xml
<?xml version="1.0" encoding="utf-8"?>
<!-- Ajout de la permission internet pour les actualités worpdress -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<!-- if you want to load images from a file OR from the internet -->
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.AlloMairie">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
谢谢 ;)
解决方案
看起来 DNS 服务器无法识别您指定的 URL。你确定https://app.divion.fr/wp-json/api/是一个实际的工作网址吗?您可以将 url 复制并粘贴到网络浏览器中,看看它是否会打开一个页面进行验证。如果它不是一个有效的 URL,请使用一个有效的 URL。
推荐阅读
- python - 如何在 pandas DataFrame 中的多个列/行中获取唯一列值的计数?
- cypress - cypress 命令重载/覆盖
- tensorflow - 没有 GPU 的神经网络和机器学习。我有什么选择?
- javascript - 你怎么能知道颜色是红色还是蓝色......有色(Javascript)
- html - 页脚与 XSLT 中的内容重叠
- visual-studio-code - 在 VS-Code 中查找任何操作(如在 Intellj 中)
- excel-formula - 如果列的对应部分不为空,则按列计数
- quarkus - Quarkus RestClient 关闭()
- php - PHP电子表格从Excel中提取和导入数据到MYSQL。内爆函数警告错误
- python - Pycharm 信号 9 出错:Mac 中的 SIGKILL