gpt4 book ai didi

java - 为什么没有发送http请求? Android Studio - 改造

转载 作者:行者123 更新时间:2023-12-02 09:02:15 32 4
gpt4 key购买 nike

我正在 Android studio 中使用 Retrofit - java。我正在尝试向特定 ip 发送 http 请求,当我尝试嗅探数据包时在模拟器中运行应用程序,我看不到发送到的列表中的任何 http 数据包具体ip。

这是我尝试发送 http 请求的地方:

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;

这是我的服务:

public interface IService
{

@POST("api/users/login")
Call<LoginResponse> Login(@Body LoginRequest loginRequest);


}

不明白我哪里做错了。谢谢。

最佳答案

在 Android View 结构中:

list -> 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>

关于java - 为什么没有发送http请求? Android Studio - 改造,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60077913/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com