改装 spring 启动无响应
retrofit spring boot not responding
我在 spring 引导中有一个服务器,它是 运行 在端口 8080 上。
现在我正在尝试使用 retrofit2 在我的 android 应用程序中调用 rest api。
这是我实现的:
final TextView textView=findViewById(R.id.t1);
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("http://localhost:8080/")
.addConverterFactory(GsonConverterFactory.create())
.build();
JsonPlaceHolderApi jsonPlaceHolderApi = retrofit.create(JsonPlaceHolderApi.class);
Call<TC> call = jsonPlaceHolderApi.getPosts();
call.enqueue(new Callback<TC>() {
@Override
public void onResponse(Call<TC> call, Response<TC> response) {
textView.setText(response.toString());
if (!response.isSuccessful()) {
return;
}
TC posts = response.body();
textView.setText(posts.toString());
}
@Override
public void onFailure(Call<TC> call, Throwable t) {
}
});
我可以肯定地说,它不起作用,因为我的 api 甚至都没有被调用。因为你好世界屏幕保持原样。
我的服务器中有记录器,它不记录任何内容,因此不会被调用。
这是我的 CORS:
@Bean
public WebMvcConfigurer corsConfigurer() {
return new WebMvcConfigurer() {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry
.addMapping("*")
.allowedOrigins("*");
}
};
}
问题出在单词 localhost
上。
至于调试目的,我正在将 android 设备与我的 PC 连接,因此我的 android 设备无法连接到 localhost
,因为它只是我 IP 的别名地址。
为了解决这个问题,我打开CMD并写入ipconfig
,通过这个命令我可以看到所有与IP相关的细节。
这里显示我的 IPv4 地址为 $.$.$.$
。我刚刚用 $.$.$.$
替换了 localhost
。
现在一切正常。
关于如何使其与 Asp.net 核心一起工作的任何想法。我只是用我的本地机器 ip 地址测试它并且工作完美。
不幸的是,Asp.net 内核并非如此。
aAndroid + Retrofit + Asp.net API "java.security.cert.CertPathValidatorException: Trust anchor for certification path not found."
我在 spring 引导中有一个服务器,它是 运行 在端口 8080 上。
现在我正在尝试使用 retrofit2 在我的 android 应用程序中调用 rest api。
这是我实现的:
final TextView textView=findViewById(R.id.t1);
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("http://localhost:8080/")
.addConverterFactory(GsonConverterFactory.create())
.build();
JsonPlaceHolderApi jsonPlaceHolderApi = retrofit.create(JsonPlaceHolderApi.class);
Call<TC> call = jsonPlaceHolderApi.getPosts();
call.enqueue(new Callback<TC>() {
@Override
public void onResponse(Call<TC> call, Response<TC> response) {
textView.setText(response.toString());
if (!response.isSuccessful()) {
return;
}
TC posts = response.body();
textView.setText(posts.toString());
}
@Override
public void onFailure(Call<TC> call, Throwable t) {
}
});
我可以肯定地说,它不起作用,因为我的 api 甚至都没有被调用。因为你好世界屏幕保持原样。
我的服务器中有记录器,它不记录任何内容,因此不会被调用。
这是我的 CORS:
@Bean
public WebMvcConfigurer corsConfigurer() {
return new WebMvcConfigurer() {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry
.addMapping("*")
.allowedOrigins("*");
}
};
}
问题出在单词 localhost
上。
至于调试目的,我正在将 android 设备与我的 PC 连接,因此我的 android 设备无法连接到 localhost
,因为它只是我 IP 的别名地址。
为了解决这个问题,我打开CMD并写入ipconfig
,通过这个命令我可以看到所有与IP相关的细节。
这里显示我的 IPv4 地址为 $.$.$.$
。我刚刚用 $.$.$.$
替换了 localhost
。
现在一切正常。
关于如何使其与 Asp.net 核心一起工作的任何想法。我只是用我的本地机器 ip 地址测试它并且工作完美。
不幸的是,Asp.net 内核并非如此。
aAndroid + Retrofit + Asp.net API "java.security.cert.CertPathValidatorException: Trust anchor for certification path not found."