Java 为什么不发送http请求?安卓工作室-改造
我正在Android studio-java中使用改型。 我正在尝试向特定ip发送http请求,当我尝试嗅探数据包时 在emulator中运行应用程序时,我看不到列表中发送到的任何http数据包 特定ip 这是我尝试发送http请求的地方:Java 为什么不发送http请求?安卓工作室-改造,java,android,http,retrofit,Java,Android,Http,Retrofit,我正在Android studio-java中使用改型。 我正在尝试向特定ip发送http请求,当我尝试嗅探数据包时 在emulator中运行应用程序时,我看不到列表中发送到的任何http数据包 特定ip 这是我尝试发送http请求的地方: IService service = retrofit.create(IService.class); Call<LoginResponse> call = service.Login(loginRequest);
IService service = retrofit.create(IService.class);
Call<LoginResponse> call = service.Login(loginRequest);
call.enqueue(new Callback<LoginResponse>() {
@Override
public void onResponse(Call<LoginResponse> call, Response<LoginResponse> response)
{
Response = response.body();
}
@Override
public void onFailure(Call<LoginResponse> call, Throwable t) {
Response = new LoginResponse("Error with the communication with the server!", null);
}
});
return (LoginResponse) Response;
IService服务=改装.create(IService.class);
Call=service.Login(loginRequest);
call.enqueue(新回调(){
@凌驾
公共void onResponse(调用、响应)
{
Response=Response.body();
}
@凌驾
失败时公共无效(调用调用,可丢弃的t){
Response=newloginresponse(“与服务器通信出错!”,null);
}
});
返回(LoginResponse)响应;
这是我的服务:
public interface IService
{
@POST("api/users/login")
Call<LoginResponse> Login(@Body LoginRequest loginRequest);
}
公共接口iSeries设备
{
@POST(“api/用户/登录”)
调用登录名(@Body LoginRequest LoginRequest);
}
我不明白我哪里做错了。
谢谢。在Android视图结构中: Manifest->AndroidManifest.xml: 还提供usesCleartextTraffic,这样您就不会在向ip发送响应时出错
<?xml version="1.0" encoding="utf-8"?>
<manifest ...>
<uses-permission android:name="android.permission.INTERNET" />
<application
...
android:usesCleartextTraffic="true"
...>
...
</application>
</manifest>
...
如果是http或https,请检查您的URL。
如果您的URL是http,并且出现此错误
网络安全不允许与**进行明文通信
政策
与此相关的是,从Android 9(API级别28)开始,明文支持在默认情况下被禁用
在这种情况下,请在AndroidManifest.xml的应用程序标记中添加以下android:usesCleartextTraffic=“true”
<application
android:name=".App"
android:allowBackup="false"
android:fullBackupContent="false"
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">
如果没有,请发布错误描述。希望对您有所帮助。您是否提供了internet权限?我该怎么做?